MISRA.DEFINE.SHARP.MANYSeveral # or ## operators in a macro definition. MISRA-C Rule 19.12 (required): The defined preprocessor operator shall only be used in one of the two standard forms.[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-3-1 (required): There shall be at most one occurrence of the # or ## operators in a single macro definition.[Unspecified 16.3.2(2), 16.3.3(3), Undefined 16.3.2(2), 16.3.3(3)] RationaleThe order of evaluation associated with both the # and ## preprocessor operators is unspecified. This problem can be avoided by having only one occurrence of either operator in any single macro definition (i.e. one #, or one ## or neither). Example#define A(x) #x // Compliant #define B(x, y) x ## y // Compliant #define C(x, y) # x ## y // Non-compliant In the following, if 'y' is joined to 'z' first then the fourth parameter of 'D' will be substituted and joined to 'x'. Alternatively, if 'x' is joined with 'y' first, then the fourth parameter of 'D' will not be substituted. #define D(x, y, z, yz) x ## y ## z // Non-compliant |