...
The following definition for static_assert()
from DCL03-A. Use a static assertion to test the value of a constant expression uses the JOIN()
macro to concatenate the token assertion_failed_at_line_
with the value of __LINE__
.
Code Block |
---|
#define static_assert(e) \ typedef char JOIN(assertion_failed_at_line_, __LINE__) \ [(e) ? 1 : -1] |
Wiki Markup |
---|
{{\_\_LINE\_\_}} is a predefined macro names which expands to an integer constant representing the presumed line number of the current source line within the current source file \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\]. |
If the intention is to expand the __LINE__
macro, which is likely the case here, the following definition for JOIN()
is non-compliant:
Code Block | ||
---|---|---|
| ||
#define JOIN(x, y) x ## y |
because the __LINE__
is not expanded, and the character array is subsequently named assertion_failed_at_line___LINE__
.
Compliant Solution
To get the macro to expand, a second level of indirection is required, as shown by this compliant solution:
...