Overloading Macro on Number of Arguments

后端 未结 8 1660
离开以前
离开以前 2020-11-22 04:25

I have two macros FOO2 and FOO3:

#define FOO2(x,y) ...
#define FOO3(x,y,z) ...

I want to define a new macro

8条回答
  •  梦如初夏
    2020-11-22 05:12

    Maybe you can use this macro to count the number of arguments.

    #define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 5,4,3,2,1)
    #define VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,N,...) N
    

提交回复
热议问题