Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

C programmers commonly make errors regarding the precedence rules of C operators due to the unintuitive low-precedence levels of &, |, ^, <<, and >>. Mistakes regarding precedence rules can be avoided by the suitable use of parentheses. Using parentheses defensively reduces errors and, if not taken to excess, makes the code more readable.

Wiki MarkupSection 6.5 of \[ [ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] (C99) defines the precedence of operation by the order of the subclauses.

Noncompliant Code Example

...

Tool

Version

Checker

Description

Section

LDRA tool suite

Include Page
c:LDRA_Vc:
LDRA_V
Section

361 S

Section

Fully Implemented

Section

ECLAIR

Include Page
c:ECLAIR_Vc:
ECLAIR_V
Section

exprprns

Section

Fully Implemented

...

MISRA Rule 12.1

Bibliography

...

\[[Dowd 2006|AA. Bibliography#Dowd 06] \] Chapter 6, "C Language Issues" (Precedence, pp. 287&mdash;288) \[287—288)
[Kernighan 1988|AA. Bibliography#Kernighan 88]\] \[[NASA-GB-1740.13|AA. Bibliography#NASA]
[NASA-GB-1740.13]\] Section 6.4.3, "C Language"

...

03. Expressions (EXP)      03. Expressions (EXP)      EXP01-C. Do not take the size of a pointer to determine the size of the pointed-to type