I see this macro appearing in many places in a code base to find if a particular field is disabled or not (0 or 1).
#define assert_disabled(e) ((void)sizeof(e))
How does sizeof
help here in finding if a field is 0 or 1?
Can someone explain this with a working example?
I'm pretty sure this macro is just being used when assertions are turned off. The trick of using ((void)sizeof(e))
instead of just (void)0
or similar is clever: it avoids evaluating e
(mostly), but still has the compiler check that e
is a valid expression, so you won't get surprise compile errors when you change the definition to turn assertions on.
This is kind of blackmagic I saw in Linux Kernel codes.
Its used to check expression 'e' at compile time.
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