Token-Pasting Operator
The token-pasting operator (##) within a macro
definition combines two arguments. It permits two separate tokens
in the macro definition to be joined into a single token.
- If the name of a macro parameter used in the macro
definition is immediately preceded or followed by the
token-pasting operator, the macro parameter and the
token-pasting operator are replaced by the value of the
parameter passed. Text that is adjacent to the
token-pasting operator that is not the name of a macro
parameter is not affected. For example:
-
#define paster(n) printf ("token" #n " = %d", token##n)
paster (9);
- results in the following actual output from the
preprocessor.
-
printf ("token9 = %d", token9);
This example shows the concatenation of token##n into token9. Both the stringize
and the token-pasting operators are used in this example.