...
If the intention is to expand the __LINE__
macro, which is likely the case here, the following definition for JOIN()
is noncompliant:
Code Block | ||||
---|---|---|---|---|
| ||||
#define JOIN(x, y) x ## y |
...
To get the macro to expand, a second level of indirection is required, as shown by this compliant solution:
Code Block | ||||
---|---|---|---|---|
| ||||
#define JOIN(x, y) JOIN_AGAIN(x, y) #define JOIN_AGAIN(x, y) x ## y |
...
This example is noncompliant if the programmer's intent is to expand the macro before stringification:
Code Block | ||||
---|---|---|---|---|
| ||||
#define str(s) #s #define foo 4 str(foo) |
...
To stringify the result of expansion of a macro argument, you must use two levels of macros:
Code Block | ||||
---|---|---|---|---|
| ||||
#define xstr(s) str(s) #define str(s) #s #define foo 4 |
...