...
Code Block | ||||
---|---|---|---|---|
| ||||
#define INCREMENT(x, max) ((x) = ((x) + 1) % (max)) |
Compliant Solution
This compliant solution uses an inline function as recommended by PRE00-C. Prefer inline or static functions to function-like macros.
Code Block | ||||
---|---|---|---|---|
| ||||
inline int increment(int *x, int max) {*x = (*x + 1) % max;} |
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.
...