arrayscpointersimplicit-conversionaddressof

How can I assign an array to pointer?


The following code:

main(){
uint8_t id = 1;
uint8_t str[] = "shutdown 1";
uint8_t* (rcm)[];

rcm = &str; //line 83

Returns the warning in line 83:

invalid lvalue in assignment

Anyone know how can I solve that? I'm stucked on this for hours...


Solution

  • If you have an array declared like

    uint8_t str[] = "shutdown 1";
    

    then a pointer to the first element of the array will look like

    uint8_t *rcm = str;
    

    If you want to declare a pointer that will point to the whole array as a single object then you can write

    uint8_t ( *rcm )[11] = &str;
    

    As for this record

    uint8_t* (rcm)[];
    

    then it is not a declaration of a pointer. It is a declaration of an array with unknown size and with the element type uint8_t *.