How can I use macro as one of other macro parameters list

后端 未结 1 1693
一向
一向 2021-01-15 06:42

Here is a dummy example:

#define DEFINE_STRUCTURE(Result, Structure, a, b, c)  int a;
#define MEMBER_INT(name, width)                       Int, name, width
         


        
相关标签:
1条回答
  • 2021-01-15 07:11

    You need to add one more step to the substitution process.

    #define DEFINE_STRUCTURE(Result, Structure, a, b, c)  int a;
    #define MEMBER_INT(name, width)                       Int, name, width
    
    #define DEFINE_STRUCTURE2(Result, Structure, x) DEFINE_STRUCTURE(Result, Structure, x)
    DEFINE_STRUCTURE2(Result, Structure,  MEMBER_INT(b, c))
    

    Remember: on an invocation of a function-like macro, arguments are identified, then each argument is separately evaluated, then the parameters are substituted by the results of the evaluation.

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