[previous] 3410 [next] Macro parameter not enclosed in ().
Macro Definition

In some macros, it is important for a parameter to be enclosed in parentheses within the replacement list. This is not the case for all macros or all parameters; it depends on how the parameter is used within the macro.

The problem arises when a macro parameter is used as an operand in certain kinds of expression. Consider the following example:


/*PRQA S 2017,3120,3198,3227,3390,3395,3401,3408,3429,3435,3453,3456 ++*/

#define SQUARE(A) (A * A)               /* Message 3410 */

extern int foo(int n)
{
    int r;
    r = SQUARE(n);
    r = SQUARE(n + 2);                  /* Message 3430 */
    return r;
}


MISRA C:2012 Rules applicable to message 3410:

Rule-20.7  (Required) Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents