...
PRE01-EX2: Macro parameters cannot be individually parenthesized when concatenating tokens using the ## operator, converting macro parameters to strings using the # operator, or concatenating adjacent string literals. The JOIN() macro below concatenates both arguments to form a new token. The SHOW() macro converts the single argument into a string literal, which is then concatenated with the adjacent string literal to form the format specification in the call to printf()passed as a parameter to printf(), as a string and as a parameter to the %d specifier. For example, if SHOW() is invoked as SHOW(66);, the macro would be expanded to printf("66" " = %d\n", 66);.
| Code Block |
|---|
#define JOIN(a, b) (a ## b) #define SHOW(a) printf(#a " = %d\n", a) |
...
| CERT C++ Secure Coding Standard | PRE01-CPP. Use parentheses within macros around parameter names |
|---|---|
| ISO/IEC TR 24772 | Operator precedence/order of evaluation [JCW] and Pre-processor Directives [NMP] |
| MISRA-C | Rule 19.1 (advisory): |
...