Macros are frequently used to make source code more readable. Macro definitions, regardless of whether they expand to a single or multiple statements (see should not conclude with a semicolon. (See guideline PRE10-C. Wrap multi-statement macros in a do-while loop.) should not conclude with a semicolon. 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. for
loops should require braces, even if it contains only a single body statement. (see See guideline 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 a semicolon at the end of the macro definition by mistake.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
Related Guidelines
This rule appears in the C++ Secure Coding Standard as : PRE11-CPP. Do not conclude macro definitions with a semicolon.
Bibliography
TODO
...
PRE10-C. Wrap multi-statement macros in a do-while loop 01. Preprocessor (PRE)