MISRA.IF.DEFINEDIncorrect 'defined' usage in #if directive. MISRA-C Rule 19.14 (required): The defined preprocessor operator shall only be used in one of the two standard forms.This rule is also covered by MISRA.ELIF.DEFINED. [Undefined 47] The only two permissible forms for the defined preprocessor operator are:
Any other form leads to undefined behaviour, for example: #if defined(X > Y) /* not compliant - undefined behaviour */ Generation of the token defined during expansion of a #if or #elif preprocessing directive also leads to undefined behaviour and shall be avoided, for example: #define DEFINED defined #if DEFINED(X) /* not compliant - undefined behaviour */ MISRA-C++ Rule 16-1-1 (required): The defined preprocessor operator shall only be used in one of the two standard forms.This rule is also covered by MISRA.ELIF.DEFINED. [Undefined 16.1(4)] RationaleThe only two permissible forms for the defined preprocessor operator are:
Any other form is a constraint violation, but this is not reported by all compliers. Example#if defined ( X > Y ) // Non-compliant — constraint violation Generation of the token defined during expansion of a '#if' or '#elif' preprocessing directive also leads to undefined behaviour and shall be avoided, for example: #define DEFINED defined #if DEFINED(X) // Non-compliant - undefined behaviour |