...
Another way to avoid this problem is to prefer inline or static functions over function-like macros. (See also PRE00-C. Prefer inline or static functions to function-like macros.)
In general, the programmer should ensure that there is no semicolon at the end of a macro definition that consists of a single statement. The responsibility for having a semicolon where needed during the use of such a macro should be delegated to the person invoking the macro.
Noncompliant Code Example
...
| Code Block | ||
|---|---|---|
| ||
#define INCREMENT(x, max) ((x) = ((x) + 1) % (max)) |
Mitigation Strategies
...
Risk Assessment
Using a semicolon at the end of a macro definition can result in the change of program control flow and thus unintended program behavior.
...