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

后端 未结 2 1039
灰色年华
灰色年华 2021-01-17 11:45

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

 #define MAKE_TYPE(myname) \\
 typedef int myname ## Id; \\
2条回答
  •  忘掉有多难
    2021-01-17 12:18

    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

提交回复
热议问题