MISRA.USE.UNKNOWNDIRUnknown preprocessor directive is used.
MISRA C 2012 Rule 20.13 A line whose first token is # shall be a valid preprocessing directiveCategory: Required Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationWhite-space is permitted between the # and preprocessing tokens. RationaleA preprocessor directive may be used to conditionally exclude source code until a corresponding #else, #elif or #endif directive is encountered. A malformed or invalid preprocessing directive contained within the excluded source code may not be detected by the compiler, possibly leading to the exclusion of more code than was intended. Requiring all preprocessor directives to be syntactically valid, even when they occur within an excluded block of code, ensures that this cannot happen. ExampleIn the following example all the code between the #ifndef and #endif directives may be excluded if AAA is defined. The developer intended that AAA be assigned to x, but the #else directive was entered incorrectly and not diagnosed by the compiler. #define AAA 2 int32_t foo ( void ) { int32_t x = 0; #ifndef AAA x = 1; #else1 /* Non-compliant */ x = AAA; #endif return x; } The following example is compliant because the text #start appearing in a comment is not a token. /* #start is not a token in a comment */ MISRA-C++ 2008 Rule 16—0—8 (required): If the # token appears as the first token on a line, then it shall be immediately followed by a preprocessing tokenUnknown preprocessor directive is used. RationaleWhen a section of source code is excluded by preprocessor directives, the content of each excluded statement is ignored until a '#else', '#elif' or '#endif' directive is encountered (depending on the context). If one of these excluded directives is badly formed, it may be ignored without warning by a compiler with unexpected consequences. The requirement of this rule is that all preprocessor directives shall be syntactically valid even when they occur within an excluded block of code. In particular, ensure that '#else' and '#endif' directives are not followed by any characters other than white-space. Compilers are not always consistent in enforcing this requirement. Example#define AAA 2 int32_t foo(void) { int32_t x = 0; ... #ifndef AAA x = 1; #else1 // Non-compliant x = AAA; #endif ... return x; } |