假设我有 x 作为字符串参数的宏 #define a(x) "this is x"
.如果我调用 a(test)
, 形成的字符串应该是 "this is test"
.
最佳答案
您期待从宏参数创建字符串,因此,正在寻找 # operator
.在类似函数的宏的替换部分中,#
符号成为将标记转换为字符串的预处理运算符。所以你需要
#define a(x) "this is " #x
或者
#define a(x) "this is " #x " in the middle."
关于c - 如何在c中的字符串宏中传递字符串参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41215174/