Macro expansion in the C language

Source: Internet
Author: User

 #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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.