开发者

What does a double hash (##) in a macro mean?

In the below code, what does the ## do?

 #define MAKE_TYPE(myname) \
 typedef int myname ## 开发者_如何学GoId; \


The ## in a macro is concatenation. Here, MAKE_TYPE(test) will expand to : typedef int testId.

From 16.3.3 (The ## operator) :

For both object-like and function-like macro invocations, before the replacement list is reexamined for more macro names to replace, each instance of a ## preprocessing token in the replacement list (not from an argument) is deleted and the preceding preprocessing token is concatenated with the following preprocessing token


icecrime is correct, but something important to point out in the definition is that the tokens need to be valid preprocessing tokens. Examples:

#define CONCAT(a,b) a ## b
CONCAT(ClassyClass, <int>); // bad, <int> is not a valid preprocessing token
CONCAT(Symbol, __LINE__); // valid as both are valid tokens
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜