![]() |
![]() |
3430 | ![]() |
||||
![]() | |||||||
| Preprocessing | REFERENCE - ISO:C90-6.3.1 Primary Expressions | ||||||
This macro argument becomes an operand in a bigger expression. The argument is not a primary expression and the parameter in the macro definition is not parenthesised; so the effects of operator precedence may produce unexpected behaviour. In the example below, message 3430 is generated for all three macros when the macro argument is not a primary expression. The call to ADD will probably function as anticipated, but the calls to MULTIPLY and COMPLEMENT will produce results which may be unexpected. In all three macros, it would be wise to parenthesise every instance of the macro parameter to avoid such problems.
/*PRQA S 2017,3198,3199,3203,3227,3390,3395,3401,3408,3429,3435,3453,3456 ++*/
#define MULTIPLY(x) ( x * x ) /* Message 3410 */
#define ADD(x) ( x + x ) /* Message 3410 */
#define COMPLEMENT(x) ( ~x ) /* Message 3410 */
extern void foo(unsigned int a, unsigned int b)
{
unsigned int r;
r = MULTIPLY(a); /* OK - expands to "a * a" */
r = ADD(a); /* OK - expands to "a + a */
r = COMPLEMENT(a); /* OK - expands to "~a" */
r = MULTIPLY(a + b); /* Message 3430 - expands to "a + b * a + b" */
r = ADD(a * b); /* Message 3430 - expands to "a * b + a * b */
r = COMPLEMENT(a & b); /* Message 3430 - expands to "~a & b" */
r = MULTIPLY((a + b)); /* OK - expands to "(a + b) * (a + b)" */
r = ADD((a * b)); /* OK - expands to "(a * b) + (a * b)" */
r = COMPLEMENT((a & b)); /* OK - expands to "~(a & b)" */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |