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 x.:

Code Block
bgColor#FFCCCC
langc
x & 1 == 0

...

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

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

...

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

Code Block
bgColor#ffcccc
langc
x + (y * z)

...

Bibliography

[Dowd 2006]Chapter 6, "C Language Issues" ("Precedence," pp. 287–288)
[ISO/IEC 9899:2011]Section 6.5, "Expressions"
[Kernighan 1988] 
[NASA-GB-1740.13]Section 6.4.3, "C Language"

...


 

...