【发布时间】:2018-07-07 17:31:40
【问题描述】:
#define STR1 "NEW"
#define STR2 PILLAR
#define MAKE_STR(x) #x
#define STR3 STR1 MAKE_STR(STR2)
printf(STR3 " hello world\n");
上面的语句扩展为
printf("NEWSTR2 hello world\n");
我需要像“NEWPILLAR hello world”这样的东西。有输入吗?
【问题讨论】:
-
其实宏扩展为
printf("NEW" "STR2" " hello world\n");。使用编译器(或等效项)的 -E 标志仅调用预处理器;不要假设 printf 打印的是预处理器所做的。
标签: c macros concatenation c-preprocessor