Versions Compared

Key

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

...

If an if, while, or for statement is used in a macro, the macro definition should not conclude with a semicolon. (See PRE11-C. Do not conclude macro definitions with a semicolon.)

Braces improve the uniformity and readability of code. More important, when inserting an additional statement into a body containing only a single statement, it is easy to forget to add braces because the indentation gives strong (but misleading) guidance to the structure.

Braces also help ensure that macros with multiple statements are properly expanded. Such a macro should be wrapped in a do-while loop. (See PRE10-C. Wrap multi-statement multistatement macros in a do-while loop.) However, when the do-while loop is not present, braces can still ensure that the macro expands as intended.

...

ISO/IEC 9899:2011 Section 6.8.4, "Selection statements"

MISRA Rule 14.8

Bibliography

[GNU 2010] Coding Standards, Section 5.3, "Clean use of C constructs"

...