[previous] 3409 [next] The replacement list of function-like macro '%s' is not enclosed in ().
Macro Definition REFERENCE - ISO:C90-6.8 Preprocessing Directives

The replacement list in this macro definition should probably be enclosed in parentheses ( ).

Message 3409 is generated when the replacement list of a macro contains arithmetic operators and is not enclosed in parentheses. When the macro is expanded the result may be unexpected because the order in which operations are performed may depend on the precedence level of operators outside the macro.

In the following example, the absence of parentheses around the replacement list of macro ADD1 gives rise to a result which is almost certainly not what is required. Macro ADD2 illustrates how the macro should probably be written.


/*PRQA S 3120,3211,3227,3395,3401,3408,3429,3447,3453 ++*/

#define ADD1(A, B)  (A) + (B)                   /* Message 3409 */
#define ADD2(A, B)  ((A) + (B))                 /*              */

#define STRINGIFY(X) #X                         /*              */
#define GLUE(X, Y) X ## Y                       /*              */

extern int r;
extern int s;

extern void foo(int a, int b)
{

/**********************************
The following statement expands to:
    r = 2 * (a) + (b);
**********************************/
    r = 2 * ADD1(a, b);


/**********************************
The following statement expands to:
    s = 2 * ((a) + (b));
**********************************/
    s = 2 * ADD2(a, b);
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents