小编unl*_*ycn的帖子

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

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

#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成功了?

c c++ c-preprocessor

6
推荐指数
1
解决办法
179
查看次数

标签 统计

c ×1

c++ ×1

c-preprocessor ×1