Rule Definition
The order of evaluation associated with both the # and ## preprocessor operators is unspecified. Compilers have been known to implement these operators inconsistently, therefore, to avoid these problems, do not use them.
Remediation
Use the # or ## operator at most once in the definition
Violation Code Sample
#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
Fixed Code Sample
#define A(x) #x // Compliant
#define B(x, y) x ## y // Compliant
Reference
MISRA C++ 2008, 16-3-1: There shall be at most one occurrence of the # or ## operators in a single macro definition.
AUTOSAR, C++ 2014, Rule M16-3-1: There shall be at most one occurrence of the # or ## operators in a single macro definition.
Related Technologies
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.