Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If the intention is to expand the __LINE__ macro, which is likely the case here, the following definition for JOIN() is noncompliant:

Code Block
bgColor#FFcccc
langc
#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
bgColor#ccccFF
langc#ccccff
#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
bgColor#FFcccc
langc
#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
bgColor#ccccFF
langc#ccccff
#define xstr(s) str(s)
#define str(s) #s
#define foo 4

...