How can I guarantee full macro expansion of a parameter before paste?

后端 未结 1 1395
攒了一身酷
攒了一身酷 2021-01-12 08:36

I have a general macro:

#define mSwitch( Root, Case )  Root##_Case_##Case

#define mSpecialDisplay( what, Val )  mSwitch(mSpecialDisplay,what)(Val)
#define m         


        
1条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 09:26

    This is the usual idiom for this:

    #define mSwitch(Root, Case) mSwitch_(Root, Case)
    #define mSwitch_(Root, Case) Root##_Case_##Case
    

    All of the arguments to a C preprocessor macro are fully expanded before the macro itself is expanded, unless the # or ## operator is applied to them; then they're not expanded. So to get full expansion before ##, you pass the arguments through a wrapper macro that doesn't use ##.

    0 讨论(0)
提交回复
热议问题