During one review I came across a piece of code like the following :
#if defined(x) || y
What does the above statement mean ? Will the condition execute properly ?
Yes it is valid.
Here is what the Standard (C99) says in 6.10p1:
if-group: # if constant-expression new-line groupopt # ifdef identifier new-line groupopt # ifndef identifier new-line groupopt
the defined
operator is seen as unary operator part of a constant expression (6.10.1p1).
In your example, the condition is evaluated as true if the macro x
is defined OR if y
is defined and different than 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