Rule Definition
If any of the arguments act like preprocessor directives, the behaviour when macro substitution is made, can be unpredictable.
Remediation
You can pass C identifiers, separated by commas and optionally whitespace but not pre-processor directives
Violation Code Sample
#define M(A) printf ( #A )
void main ( )
{
M(
#ifdef SW // Non-compliant: a conditional compilation is passed as an argument
"Message 1"
#else // Non-compliant
"Message 2"
#endif // Non-compliant
);
}
Reference
MISRA C++, 2008, 16–0–5: Arguments to a function-like macro shall not contain tokens that look like preprocessing directives.
AUTOSAR, C++, 2014, M16-0-5: Arguments to a function-like macro shall not contain tokens that look like pre-processing directives.
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.