What's the meaning of "##" in the following?

#define CC_SYNTHESIZE(varType, varName, funName)\ protected: varType varName;\ public: inline varType get##funName(void) const { return varName; }\ public: inline void set##funName(varType var){ varName = var; } 
0

3 Answers

The operator ## concatenates two arguments leaving no blank spaces between them: e.g.

#define glue(a,b) a ## b glue(c,out) << "test"; 

This would also be translated into:

cout << "test"; 

It concatenates tokens without leaving blanks between them. Basically, if you didn't have the ## there

public: inline varType getfunName(void) const { return varName; }\ 

the precompiler would not replace funName with the parameter value. With ##, get and funName are separate tokens, which means the precompiler can replace funName and then concatenate the results.

0

This is called token pasting or token concatenation.

The ## (double number sign) operator concatenates two tokens in a macro invocation (text and/or arguments) given in a macro definition.

Take a look here at the official GNU GCC compiler documentation for more information.