Versions Compared

Key

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

...

The intent of the expression in this noncompliant code example is to test the least significant bit of xadd the variable OFFSET with the result of bitwise anding x and MASK.

Code Block
bgColor#FFCCCC
x & 1MASK ==+ 0OFFSET

Because of operator precedence rules, the expression is parsed as

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

which evaluates to

Code Block
bgColor#FFCCCC
(x & 0+ OFFSET)

and then to 0.

Compliant Solution

In this compliant solution, parentheses are used to ensure the expression evaluates as expected.

Code Block
bgColor#ccccff

(x & 1MASK) ==+ 0OFFSET

Exceptions

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

Code Block

x + y * z

the multiplication is performed before the addition by mathematical convention. Consequently, parentheses to enforce this would be redundant.

...