6.13.2 Concatenation (##)
The concatenation operator concatenates two preprocessor tokens, forming a new token. It is most useful when at least one of the tokens are a parameter to a function-type macro.
Example
#define FOOBAR subi
#define IMMED(X) X##i
#define SUBI(X,Y) X ## Y
When the IMMED
and SUBI
macros
are called like this:
IMMED(ld) r16,1
SUBI(FOO,BAR) r16,1
they will be expanded to
ldi r16,0x1
subi r16,0x1
Note:
- The concatenation operator cannot appear first or last in a macro expansion.
- When used on a function-type macro argument, the argument will be used literally, i.e., it will not be expanded before concatenation.
- The token formed by the
concatenation will be subject to further expansion. In example 2 above, the
parameters
FOO
andBAR
are first concatenated toFOOBAR
, thenFOOBAR
is expanded tosubi
.