The ## (double number sign) operator concatenates two tokens in a macro invocation (text and/or arguments) given in a macro definition.
If a macro XY was defined using the following directive:
#define XY(x,y) x##y
the last token of the argument for x is concatenated with the first token of the argument for y.
For example,
Invocation | Result of Macro Expansion |
---|---|
XY(1, 2) | 12 |
XY(Green, house) | Greenhouse |
Use the ## operator according to the following rules:
The following examples demonstrate the use of the ## operator:
#define ArgArg(x, y) x##y #define ArgText(x) x##TEXT #define TextArg(x) TEXT##x #define TextText TEXT##text #define Jitter 1 #define bug 2 #define Jitterbug 3
Invocation | Result of Macro Expansion |
---|---|
ArgArg(lady, bug) | ladybug |
ArgText(con) | conTEXT |
TextArg(book) | TEXTbook |
TextText | TEXTtext |
ArgArg(Jitter, bug) | 3 |
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.