3

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; }
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Best Water
  • 169
  • 3
  • 14

3 Answers3

8

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";
Ed Heal
  • 59,252
  • 17
  • 87
  • 127
1

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.

aleroot
  • 71,077
  • 30
  • 176
  • 213
1

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.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294