Nested Macro : Order of Expansion

13,818

It's a consequence of how macros are expanded, and has an impact on self-referential macros... This is quite nicely explained in detail in the GNU CPP manual

Share:
13,818
Amol Sharma
Author by

Amol Sharma

Computer Science Student @ MNNIT Allahabad

Updated on June 15, 2022

Comments

  • Amol Sharma
    Amol Sharma almost 2 years

    Possible Duplicate:
    Why i am not getting the expected output in the following c programme?

    i am having a doubt in order of evaluation of macros.like for the following code i am not able to understand the ouput:

    #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 not f is getting expanded first before g in the second printf ?