0
typedef struct state1_s {
    u8 size;
    u8 state;
} state1_t;
typedef struct state2_s {
    u8 size;
    u8 state[2];
} state2_t;
typedef struct state3_s {
    u8 code;
    u8 count;
}state3_t;

I have these three structures. When i do the following

state1_t comp[8];
state2_t *avail;
state3_t *health;

&comp = (state1_t *)(&(avail->state[2])+1);

i get a expression must be modifiable lvalue error.

I get the same error when i do

&comp = (state1_t *)(&(heaalth->count) +1);

how do i fix this? I want the address of comp to be at the end of one structure. How do i do that?

2 Answers2

0

state1_t comp[8];

In this declaration comp is an array of 8 struct's state1_t with base address of the array being comp which cannot be modifiable. Hence the modifiable lvalue error when you try changing address of comp.

Sunil Bojanapally
  • 12,528
  • 4
  • 33
  • 46
0

You can't change the address of an array. You should use a pointer instead:

state1_t *comp;

Then you can do:

comp = (state1_t *)(&(avail->state[2]));

You don't need to add 1 to the address -- state[2] is already the end of the structure, since state[1] is the last element of that array.

Barmar
  • 741,623
  • 53
  • 500
  • 612