I've seen the following code snippet.
The output is
I GUESS that in the first printf(), firstly, it is replacing h(f(1,2)) by g(f(1,2)), and then immediately in the same pass, it calculated its argument i.e. f(1,2), resulting in "12". Thus getting g("12") in place of h(f(1,2)). This g("12") results in a string "12".
In short, in first printf()
h(f(1,2)) >> g("12") >> "12"
In the second printf(),
g(f(1,2)) >> "f(1,2)"
I'm not sure about this guesswork. Still some questions remain. Please put some light on it. How many passes does a C pre-processor performs? And exactly how it works? Please explain it.
Thank you.
Code:
#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;
}
Code:
12 f(1,2)
In short, in first printf()
h(f(1,2)) >> g("12") >> "12"
In the second printf(),
g(f(1,2)) >> "f(1,2)"
I'm not sure about this guesswork. Still some questions remain. Please put some light on it. How many passes does a C pre-processor performs? And exactly how it works? Please explain it.
Thank you.
Comment