Versions Compared

Key

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

...

Inline functions are, in general, more suitable for this task. (See guideline recommendation PRE00-C. Prefer inline or static functions to function-like macros.) Occasionally, however, they are not feasible (when macros are expected to operate on variables of different types, for example).

When multiple statements are used in a macro, they should be bound together in a do-while loop syntactically, so the macro can appear safely inside if clauses or other places that expect a single statement or a statement block. (Alternatively, when an if, for or while statement uses braces even for a single body statement, then multiple statements in a macro will expand correctly even without a do-while loop. See guideline recommendation EXP19-C. Use braces for the body of an if, for, or while statement.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

CERT C++ Secure Coding Standard: PRE10-CPP. Wrap multi-statement macros in a do-while loop

Bibliography

unmigrated-wiki-markup

\[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] TR 24772 "NMP Pre-processor Directions" [

Bibliography

Linux Kernel Newbies FAQ|http://kernelnewbies.org/FAQ] [FAQ/DoWhile0|http://kernelnewbies.org/FAQ/DoWhile0]

...

      01. Preprocessor (PRE)