I came across this example of an assertion and was wondering what the #
is for:
#define ASSERT( x ) if ( !( x ) ) { \
int *p = NULL; \
DBGPRINTF("Assert failed: [%s]\r\n Halting.", #x); \
*p=1; \
}
I came across this example of an assertion and was wondering what the #
is for:
#define ASSERT( x ) if ( !( x ) ) { \
int *p = NULL; \
DBGPRINTF("Assert failed: [%s]\r\n Halting.", #x); \
*p=1; \
}
It is the "stringize" preprocessing operator.
It takes the tokens passed as the argument to the macro parameter
x
and turns them into a string literal.It's the stringizing operator.
http://msdn.microsoft.com/en-us/library/7e3a913x(v=vs.80).aspx
It's a preprocessor feature called stringification. It
#
is the preprocessor's "stringizing" operator. It turns macro parameters into string literals. If you calledASSERT(foo >= 32)
the#x
is expanded to"foo >= 32"
during evaluation of the macro.#x
is the stringification directive#define Stringify(x) #x
means
Stringify(abc)
will be substituted with"abc"
as in
#
is the stringizing operator defined in Section 6.10.3.2 (C99) and in Section 16.3.2. (C++03)It converts macro parameters to string literals without expanding the parameter definition.
For instance, syntactically, occurrences of the backslash character in string literals are limited to escape sequences.
In the following example:
the result of the
#
operator need not be"a \ b"
.