This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

array to array

for example i have got three constant array

code unsigned char a_0[]={0x54,0x25,0x11,0xff,0x21};
code unsigned char a_1[]={0x51,0x45,0x55,0x85};
code unsigned char a_2[]={0x24,0x47};

in program i want to use this costant similar this;
send(a[0]);
or i=2;
send(a[i]);

how can i do this, all my constant have got different size

  • code unsigned char a[3][5]={{0x54,0x25,0x11,0xff,0x21},
                             {0x51,0x45,0x55,0x85},
                             {0x24,0x47}};
    
    
    

    for example i can use send(a[2]); but this spend more memory location then which i need. i try to find a different way.

  • send(a[i]);
    

    This can't work. Something has to tell this function how many bytes there are in the array you want to send. Objects of different size can't be part of the same array without wasting some memory, so you have to get the size from somewhere else.

    The closest you can do is

    send(a_0, sizeof(a_0))
    


    or, slightly more complex:

    struct {
      u8 *ptr;
      size_t len;
    } a[] = {
       a_0, sizeof(a_0);
       a_1, sizeof(a_1);
       a_2, sizeof(a_2);
    };
    
    /*...*/
    send(a[i].ptr, a[i].len)