Monday, October 29, 2007

C++ note: operator precedence

Another common trap is the precedence between == and & | ^

The expression a & b == 0 is interpreted as a & (b==0) instead of (a & b) == 0, quite different from a + b == 0.

Conclusion: always add brackets when evaluating the bitwise operators & | ^

No comments: