當我使用此代碼:「#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