I found this in an old kernel code :
#define hlist_for_each_entry(tpos, pos, head, member) \
for (pos = (head)->first; \
pos && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
but I don't understand how I should interpret the meaning of this line:
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});
How does the compiler undersand the meaning of more than one expression inside braces/parentheses (the ({...;...;}) construct)?
It seems that this construction
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});
is based on its own language extension of the compiler and allows to use compound statements in expressions. It is similar to lambda expressions in C++.
I think that the result of evaluation of the construction has value 1.
In my opinion it is simply a bad code because the same can be written using the comma operator like
pos && ( ( tpos = hlist_entry(pos, typeof(*tpos), member) ), 1 ); \
pos = pos->next)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With