#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 %s\n , G (F (1 , 2 return 0 ;}
How to expand the rules for a macro function: when the current macro function is expanded, if the parameter has # or # #则不进行宏参数的展开, expand the macro argument first, and then expand the current macro.
The Almighty StackOverflow
Http://stackoverflow.com/questions/1686324/how-does-this-c-code-work
Http://stackoverflow.com/questions/4364971/and-in-macros
http://zjf30366.blog.163.com/blog/static/411164582009061075923/
Analysis:
x# #y把两个符号连起来 XY
#a指把a当成符号 is to think of the string behind the #
#define F (A, B) a# #b # define G (a) #a # define H (a) g (a)
printf ("%s\n", H (f ())); Results 12
Because the argument in the H macro is another macro with # #, the macro as a parameter is not expanded
printf ("%s\n", G (f))); Results f (+)
Because the argument in the G macro is another macro, but without # #, the macro as a parameter expands first
When you expand the current macro function, if the parameter has a # or # #则不进行宏参数的展开, expand the macro argument first, and then expand the current macro.
Macro expansion in the C language