0

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...

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • You can't assign an array to a pointer. But you can assign a pointer to a pointer. Like `uint8_t ptr = str;` – Some programmer dude Oct 10 '21 at 11:23
  • 1
    As for the problem for your current code, you declare `rcm` to be an array of pointers, not a pointer to an array. The type of `&str` is `uint8_t (*)[11]` (and yes, the size is part of the type). – Some programmer dude Oct 10 '21 at 11:24
  • If you want `str` to be an array of characters, define `str` as `char str[] = "shutdown 1";`, you can access a pointer to the first element of the array by just accessing `str` – Ben Oct 10 '21 at 12:06

1 Answers1

1

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 *.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • Thanks for the answers! I missed the pointer size, anyway I'm still stucked on that. I'll post the entire code regarding the same issue. – Andrea Strappato Oct 10 '21 at 11:54