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,030
  • 21
  • 100
  • 124
Best Water
  • 169
  • 2
  • 14

3 Answers3

7

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
  • 57,599
  • 16
  • 82
  • 120
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
  • 68,849
  • 28
  • 172
  • 209
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
  • 170,943
  • 22
  • 265
  • 283