Nested Macros: Extension Order

Possible duplicate:
Why am I not getting the expected result in the next program c?

I have doubts about how to evaluate macros. As for the following code, I cannot figure out the output:

#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; } 

Output

 12 f(1,2) 

why doesn't f first expand to g in the second printf?

+4
source share
1 answer

This is a consequence of how macros expand and affect self-referencing macros ... This is explained in some detail in the GNU CPP manual.

+1
source

Source: https://habr.com/ru/post/1387013/


All Articles