Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Non-Compliant Code Example

The following C expression, intended intent of the expression in this non-compliant code example is to test the least significant bit of x.

Code Block
bgColor#FFCCCC
x & 1 == 0

However, it Because of operator precedence rules, the expression is parsed as

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

which the compiler would probably evaluate at compile time evaluates to

Code Block
bgColor#FFCCCC
(x & 0)

and then to 0.

Compliant Solution

Adding parentheses to indicate precedence will cause the expression to evaluate In this compliant solution, parentheses are used to ensure the expression evaluates as expected.

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

...