4 ms·
The actual line is #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) The guy asking the question just misread the code, the colon is part of the st
by xd 15y ago
The actual line is #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
The guy asking the question just misread the code, the colon is part of the struct definition and the key part is -!! which coerces an integer to 0 if the value is zero, or -1 if the value is anything other than 0.
- tesseract 15y agoYou do have to know about the bitfield struct syntax which, as C features go, seems to be one of the more obscure.
- ajross 15y agoThey're all key parts. Note that the sizeof is there to avoid polluting the namespace. Otherwise you'd have to declare something that used that anonymous struct. And likewise the parentheses so it can be used in all contexts in an expression. Every byte of that macro is needed. It's pretty elegant, honestly.
- nash 15y agoThe sizeof is there so it returns a value so it can be used as an expression. See the comment above the code (reproduced in the original question).