MISRA.EXPANSION.DIRECTIVEDirective-like tokens within a macro argument.
MISRA C 2012 Rule 20.6: Tokens that look like a preprocessing directive shall not occur within a macro argumentC90 [Undefined 50], C99 [Undefined 87] Category: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 RationaleAn argument containing sequences of tokens that would otherwise act as preprocessing directives leads to undefined behaviour. Example#define M( A ) printf ( #A ) #include <stdio.h> void main ( void ) { M ( #ifdef SW /* Non-compliant */ "Message 1" #else /* Non-compliant */ "Message 2" #endif /* Non-compliant */ ); } The above may print #ifdef SW "Message 1" #else "Message 2" #endif or "Message 2" or exhibit some other behaviour. MISRA-C 2004 Rule 19.9 (required): Arguments to a function-like macro shall not contain tokens that look like preprocessing directivesDirective-like tokens within a macro argument. [Undefined 50] If any of the arguments act like preprocessor directives, the behaviour when macro substitution is made can be unpredictable. MISRA-C++ 2008 Rule 16-0-5 (required): Arguments to a function-like macro shall not contain tokens that look like preprocessing directives.[Undefined 16.3(10)] RationaleIf any of the arguments act like preprocessor directives, the behaviour when macro substitution is made can be unpredictable. Example#define M(A) printf ( #A ) void main ( ) { M( #ifdef SW // Non-compliant "Message 1" #else // Non-compliant "Message 2" #endif // Non-compliant ); } The above may print #ifdef SW "Message 1" #else "Message 2" #endif or Message 2 |