C 预处理器如何用##扩展宏?

unl*_*ycn 6 c c++ c-preprocessor

英语不是我的母语;因此我展示了要描述的代码。

#define concat_temp(x, y) x##y
#define concat(x, y) concat_temp(x, y)
#define BAR 2

int main() {
    concat_temp(FOO, BAR)
    concat(FOO, BAR)
}
Run Code Online (Sandbox Code Playgroud)

当我执行时clang -E,宏被扩展为

int main() {
    FOOBAR
    FOO2
}
Run Code Online (Sandbox Code Playgroud)

谁能向我解释为什么concat_temp不能扩展barto2concat成功了?

iBu*_*Bug 5

根据CppReference

替换列表中任意##两个连续标识符之间的运算符对两个标识符(首先不进行宏扩展)运行参数替换,然后连接结果。

##运算符对标识符本身进行操作,因此如果您想“生成字符串文字”或连接#define-d 宏的值,则需要另一遍宏扩展。