A Mutable Log

A blog by Devendra Tewari


Project maintained by tewarid Hosted on GitHub Pages — Theme by mattgraham

Operator precedence

Programmers should use parentheses more often. The following C language snippets are mind-blowing examples of when operator precedence is not obvious and can bite you.

x & 0x01 == 0

Here, == is evaluated first and then &.

a + b ^ c + d

Here, * is evaluated first and then ^.

SEI CERT C Coding Standard actually have rules against depending on operator precedence, for instance EXP00-C.