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

3
  • You can't assign an array to a pointer. But you can assign a pointer to a pointer. Like uint8_t ptr = str; Commented Oct 10, 2021 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). Commented Oct 10, 2021 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 Commented Oct 10, 2021 at 12:06

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.