Versions Compared

Key

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

Macros are frequently used to make source code more readable. Macro definitions, regardless of whether they expand to a single or multiple statements, should not conclude with a semicolon. (See PRE10-C. Wrap multistatement macros in a do-while loop.) If required, the semicolon should be included following the macro expansion. Inadvertently inserting a semicolon at the end of the macro definition can unexpectedly change the control flow of the program.

...

This noncompliant code example creates a macro definition for a for loop in the program. A for loop should require braces, even if it contains only a single body statement. (See EXP19-C. Use braces for the body of an if, for, or while statement.) This macro takes an integer argument, which is the number of times the loop should run. The programmer has provided inserted a semicolon at the end of the macro definition by mistake.

...

In this noncompliant code example, the programmer defines a macro that increments the value of the first argument, x, by one 1 and modulates it with the value of the second argument, max:

...