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

SR:  12.3#1Checked automatically with code checker

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