...
While not yet available in C, this behavior can be mimicked as follows:
Code Block |
---|
#define JOIN(x, y) JOIN_AGAIN(x, y)
#define JOIN_AGAIN(x, y) x ## y
#define compile_time_assert(e) \
typedef char JOIN(assert_, __LINE__) [(e) ? 1 : -1]
int main(void) {
static_assert(sizeof(int) <= sizeof(long), "sizeof(int) <= sizeof(long)"); /* Passes */
static_assert(sizeof(double) <= sizeof(int), "sizeof(double) <= sizeof(int)"); /* Fails */
}
|
Wiki Markup |
---|
The {{JOIN()}} macro used the {{##}} operator \[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] can be used to concatenate tokens. to concatenate tokens. See \[[PRE05-A. Use ## sparingly and with caution]] to understand how macro replacement behaves in C when using the {{##}} operator. |
The macro argument string-literal
is ignored in this case, this is meant for future compatibility.
...