C/C++ Programmer's Guide (G06.25+)
Preprocessor Directives and Macros
HP C/C++ Programmer’s Guide for NonStop Servers—429301-002
12-17
Preprocessor Operators
to be expanded into:
"testing"
Operator ##
The binary operator ## is used in both object-like and function-like macros. It allows
you to concatenate two tokens, and therefore it cannot occur at the beginning or at the
end of the macro definition.
If a formal parameter in a macro definition is preceded or followed by the ## operator,
the formal parameter is immediately replaced by the unexpanded actual argument.
Macro expansion is not performed on the argument prior to replacement. Then, each
occurrence of the ## operator in the replacement-list is removed, and the tokens
preceding it and following it are concatenated. The resulting token must be a valid
token. If it is, the resulting token is available for further macro replacement.
Example
#define debug(s, t) printf("x" # s "= %d, x" # t "= %s",\
x ## s, x ## t )
main ()
{
debug(1, 2);
}
After the preprocessor pass, you have:
int main(void)
{
...printf("x1= %d, x2= %s", x1, x2);