这个程序的两个输出结果为什么不一样啊?
#include <stdio.h>#define f(a,b) a##b#define g(a) #a#define h(a) g(a)int main(){ printf("%s\n",h(f(1,2))); printf("%s\n",g(f(1,2))); return 0;}int main(){ printf("%s\n","12"); printf("%s\n","f(1,2)"); return 0;}
[解决办法]
h(f(1,2))=>g(a##b)=>"12"
g(f(1,2))=>"f(1,2)"
[解决办法]
楼上都是正解
[解决办法]
printf("%s\n",h(f(1,2)));004113AE mov esi,esp 004113B0 push offset string [color=#FF0000]"12"[/color] (415750h) 004113B5 push offset string "%s\n" (41574Ch) 004113BA call dword ptr [__imp__printf (4182B4h)] 004113C0 add esp,8 004113C3 cmp esi,esp 004113C5 call @ILT+310(__RTC_CheckEsp) (41113Bh) printf("%s\n",g(f(1,2)));004113CA mov esi,esp 004113CC push offset string [color=#FF0000]"f(1,2)"[/color] (415744h) 004113D1 push offset string "%s\n" (41574Ch) 004113D6 call dword ptr [__imp__printf (4182B4h)] 004113DC add esp,8 004113DF cmp esi,esp 004113E1 call @ILT+310(__RTC_CheckEsp) (41113Bh)
[解决办法]
h(f(1,2))->#1##2->"12"g(f(1,2))->#f(1,2)->"f(1,2)"