1

I get this error error: assignment to expression with array typ when I try this:

clients[0].data->bottle = x->bottle;

This is my code:

typedef struct {
    int id;
    some_data x;
    uint64_t weight;
    some_other_data_t *data;
} CLIENTS;

typedef struct {
    uint8_t bottle[10];
} some_other_data_t;

some_other_data_t x; 
extern CLIENTS clients[5];

/* some functions that set x correctly... */

clients[0].id = 1;                   // works fine!
clients[0].data->bottle = x->bottle; // does not work :(

Why is it so easy to set the id but so hard to set the data ? I even tried to cast data to char* and use strcpy to set data but it doesn't work... How can I set data?

I googled a lot but I didnt find a solution...

11
  • array, unlike a pointer is a physically bound datatype. So you can fill an array, not reassign it, it's been already assigned Commented Oct 17, 2017 at 11:02
  • 1
    So you may use functions like memcpy to copy content of x->bottle to data->bottle Commented Oct 17, 2017 at 11:04
  • @user3159253 pointers are the same; the difference is that assignment operator works for pointers but not arrays Commented Oct 17, 2017 at 11:06
  • The line above doesn't appear in your code below. And the code below would give different compilation errors than the one you gave (e.g. you are using x like a pointer when it is a struct). Commented Oct 17, 2017 at 11:07
  • @M.M perhaps I didn't expressed it correctly. I mean: arrays have allocated fixed space and this space can't be "assigned" at once, only "filled" in cycle, while pointers, well, point to an arbitrary location and thus can be reassigned to any other location. Commented Oct 17, 2017 at 11:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.