I am trying to solve this error, but failed miserably. I have declared my code below
msc_con_list_slot msc_slot;
memset(&msc_slot, 0, sizeof(msc_slot));
msc_pdn_con_t*conn = &msc_slot.conn;
msc_ber_list_slot bearer_slot;
memset(&bearer_slot, 0, sizeof(bearer_slot));
msc_ber_t *bearer = &bearer_slot.bearer;
and tried to iterate it
for(&bearer_slot=(&(conn->bearers))->head; &bearer_slot; &bearer_slot=(&bearer_slot)->next)
{
//asign value here
}
I got an error of :
lvalue required as left operand of assignment
warning: the address of ‘bearer_slot’ will always evaluate as ‘true’
Maybe I miss something, because I don’t really get what is the error actually mean is. Thank you for your help
edit add struct:
typedef struct {
int id;
} msc_ber_t;
typedef struct _msc_ber_list_slot {
msc_ber_t bearer;
struct _msc_ber_list_slot *next, *prev;
} msc_ber_list_slot;
typedef struct {
msc_ber_list_slot *head, *tail;
} msc_ber_list;
In the for loop, you are assigning values to
&bearer_slot, that is, the address of the variablebearer_slot, which is not allowed (it is not anlvalue) and makes no sense. Furthermore, your loop condition is the value of&bearer_slot, which will always evaluate totrue(as it is a non-NULLpointer), so your loop will run forever. You will need to provide more context on what you want this loop to do. By the way,(&x)->ycan be written more succinctly asx.y– this would make your code a lot more readable.