3
在#define宏中用作变量前缀时,#符号的含义是什么?奇怪的C宏语法(#var)
例如,
#define my_setopt(x,y,z) _my_setopt(x, 0, config, #y, y, z)
在#define宏中用作变量前缀时,#符号的含义是什么?奇怪的C宏语法(#var)
例如,
#define my_setopt(x,y,z) _my_setopt(x, 0, config, #y, y, z)
这是Stringizing Operator,其宏参数转换为字符串文字。
所以在你的例子:
my_setopt(1, 2, 3)
将扩展为:
_my_setopt(1, 0, config, "2", 2, 3)
#
报价的表达。例如:
#define SHOW(BAR) printf("%s is %d\n", #BAR , BAR)
SHOW(3+5); // prints: 3+5 is 8