Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

and bitwise operator in C preprocessor

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?

like image 659
user1433755 Avatar asked Mar 12 '13 03:03

user1433755


1 Answers

Order of operation seems to be the culprit since == is evaluated before &. Parentheses worked for me:

#if (10 & 10) == 10
like image 116
chrisaycock Avatar answered Sep 27 '22 20:09

chrisaycock