Reputation: 77
When I try the following code:
#if 11 & 10 == 10
#endif
the evaluation of expression is true but when I change that to the following:
#if 10 & 10 == 10
#endif
The evaluation returns false, while based on definition of & operator it should still return true (when I am trying out of preprocessor that's correct). Generally, Whatever I am trying which has 0 in the first operand returns false ignoring what the result is.
Does anyone know what the problem is?
Upvotes: 5
Views: 4505
Reputation: 3375
==
has higher precedence than &
if 11 & 10 == 10
evaluates to if 11 & 1
evaluates to if 1
if 10 & 10 == 10
evaluates to if 10 & 1
evaluates to if 0
Upvotes: 5
Reputation: 37930
Order of operation seems to be the culprit since ==
is evaluated before &
. Parentheses worked for me:
#if (10 & 10) == 10
Upvotes: 7