MISRA.DEFINE.WRONGNAME.C99.2012A macro shall not be defined with the same name as a keyword MISRA C 2012 Rule 20.4: A macro shall not be defined with the same name as a keywordC90 [Undefined 56], C99 [Undefined 98] Category: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationThis rule applies to all keywords, including those that implement language extensions. RationaleUsing macros to change the meaning of keywords can be confusing. The behaviour is undefined if a standard header is included while a macro is defined with the same name as a keyword. The following example is non-compliant because it alters the behaviour of the int keyword. Including a standard header in the presence of this macro results in undefined behaviour. Example#define int some_other_type #include <stdlib.h> The following example shows that it is non-compliant to redefine the keyword while but it is compliant to define a macro that expands to statements. #define while( E ) for ( ; ( E ) ; ) /* Non-compliant - redefined while */ #define unless( E ) if ( ! ( E ) ) /* Compliant */ #define seq( S1, S2 ) do { \ S1; S2; } while ( false ) /* Compliant */ #define compound( S ) { S; } /* Compliant */ The following example is compliant in C90, but not C99, because inline is not a keyword in C90. /* Remove inline if compiling for C90 */ #define inline See alsoRule 21.1 |