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

Rule:  6.10.3.cChecked automatically with code checker

Synopsis:Any instance of macro parameters, macro body and macro operations shall be enclosed within parenthesis.
Language:C
Severity Level:8
Category:Preprocessing Directives


Description:

Justification

Omitting parenthesis around macro parameters, macro body or macro operations can lead to unexpected interpretation of the source code.

Example 1

#define C    A + B /* WRONG */

x = 3 * C; /* this would evaluate to 3*A + B */

Example 2

#define C    (A + B) /* RIGHT */

x = 3 * C; /* this evaluates to 3*(A + B) */

Example 3

#define NOK 1 /* RIGHT */
#define GOOD (-1) /* RIGHT */
#define SQUARE(a) ((a) * (a)) /* RIGHT */

#define BAD -1 /* WRONG */
#define AWFUL(a,b) a * b /* WRONG */

x = AWFUL(1 + 1, 1) * 4; /* looks like 8... */
x = 1 + 1 * 1 * 4; /* ... but is 5 instead */