TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

Guideline:  12.3#2Checked automatically with code checker

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))