当我使用此代码:“#define STR(x)#x”和“#define STR(x)VAL(x)”与“#define VAL(x)#x”之间的区别是什么?
#include <stdio.h>
#define STR(x) #x
int main(void)
{
printf(__FILE__ STR(__LINE__) "hello!\n");
return 0;
}
它打印
hello.c__LINE__hello!
但是当我使用这个:
#include <stdio.h>
#define STR(x) VAL(x)
#define VAL(x) #x
int main(void)
{
printf(__FILE__ STR(__LINE__) "hello!\n");
return 0;
}
它打印
hello.c7hello!
有什么区别其中,宏参数名称出现在与stringifier#或令牌贴纸##的宏体参数传递给宏
和 之间#define STR(x) #x
#define STR(x) VAL(x)
#define VAL(x) #x
如果您先定义VAL(X),该怎么办?你有相同的结果吗? – I82Much
是的,与先定义STR(x)一样 – vv1133
可能重复[宏扩展的确切步骤是什么?](http://stackoverflow.com/questions/6742501/whats-the-exact-step-of-macro扩展) – codaddict