Reputation: 1
Sorry, but i am having the following difficulty in a c code. what is the 3rd line for:
#define LIST_FOR_EACH_SAFE(ITER, NEXT, MEMBER, LIST) \
for (INIT_CONTAINER(ITER, (LIST)->next, MEMBER); \
(&(ITER)->MEMBER != (LIST) \
? INIT_CONTAINER(NEXT, (ITER)->MEMBER.next, MEMBER), 1 \
: 0); \
(ITER) = (NEXT))
The entire code can be found at: https://github.com/openvswitch/ovs/blob/ff261703821658243bba13c80311130d036eeb52/include/openvswitch/list.h
SORRY, but this might take up some time for you to get the entire code.
Upvotes: 0
Views: 73
Reputation: 1168
This is not a function but a macro so you won't see what types different variables have in any declaration. However, at the second row you can see (LIST)->next
which makes it safe to assume that LIST
is a pointer to a struct which contains a member called next.
The third row with &(ITER)->MEMBER != (LIST)
compares this pointer that LIST
points to with the address of MEMBER
which is part of a structure that ITER
points to.
At the fourth row INIT_CONTAINER(NEXT, (ITER)->MEMBER.next, MEMBER)
is called only if the comparision at row 3 differs. After this call is made 1
is the result which is used to continue the for-loop.
At the fift row you instead get result 0
to end the for-loop if the comparision at row 3 would be equal.
Upvotes: 1