Synopsis: | Always enclose any instances of macro parameters 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 BAD -1 #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 OK 0 #define GOOD (-1) #define SQUARE(a) ((a) * (a)) |