...
The ##
preprocessing operator is used to merge two tokens into one while expanding macros. This is called token pasting or token concatenation. When a macro is expanded, the two tokens on either side of each ##
operator are combined into a single token, which replaces the ##
and the two original tokens in the macro expansion [FSF 2005].
...
__LINE__
is a predefined macro names which expands name that expands to an integer constant representing the presumed line number of the current source line within the current source file [ISO/IEC 9899:2011]. 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
|
Because because the __LINE__
is not expanded, and the character array is subsequently named assertion_failed_at_line___LINE__
.:
Code Block | ||||
---|---|---|---|---|
| ||||
#define JOIN(x, y) x ## y
|
Compliant Compliant Solution
To get the macro to expand, a second level of indirection is required, as shown by this compliant solution:
...
JOIN(x, y)
calls JOIN_AGAIN(x, y)
so that , if x
or y
is a macro, it is expanded before the ##
operator pastes them together.
...
The macro invocation xstr(foo)
expands to 4
. This is because s
is stringified when it is used in str()
, so it is not macro expanded first. However, s
is an ordinary argument to xstr()
, so it is completely macro expanded before xstr()
is expanded. Consequently, by the time str()
gets to its argument, it has already been macro expanded.
...
[FSF 2005] Section 3.4, "Stringification," and Section 3.5, "Concatenation"
[Saks 2008]
...