For example:
#define FOO(x) (printf(x))
and
#define FOO(x) {printf(x)}
It seems that both are viable for preprocessing, but which is better?
If you're treating the macro as an expression, use the ()
form.
If you're treating it as a command (and never as an expression) then use the {}
form. Or rather, use the do{}while(0)
form as that has fewer substitution hazards when used near keywords like if
:
#define FOO(x) do { \
printf(x); \
} while(0)
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