Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added an NCCE+CS that i've seen in real code

...

Code Block
bgColor#ccccff
(x & 1) == 0

Non-Compliant Code Example

It is common for C programmers to assign the return value of a function while concurrently checking for and in-band error condition.

Code Block
bgColor#ffcccc

if(ret = foo() != err) {
  /* use ret */
}

However, since comparison binds tighter than assignment, the value of the comparison is stored in ret. So if foo() succeeds, ret will always be set to 0, and the if-statement will execute if and only if foo() fails, contrary to the expectation of the programmer.

Compliant Solution

Code Block
bgColor#ccccff

if((ret = foo()) != err) {
  /* use ret */
}

Exceptions

EXP00-EX1: Mathemtical expressions that follow algebraic order do not require parentheses. For instance, in the expression:

...