Synopsis: | If a macro body contains any operator, enclose it within parentheses. |
Language: | C |
Severity Level: | 1 |
Category: | PREPROCESSING |
Description: |
Omitting parentheses around macro bodies and parameters can lead to unexpected
interpretation of the expanded code (as in the AWFUL example given).
Example: #define AWFUL(a,b) a * b ... x = AWFUL(1 + 1, 1) * 4; /* looks like 8... */ x = 1 + 1 * 1 * 4; /* ... but is 5 instead */ Example: #define SQUARE(a) ((a) * (a)) |