vendredi 21 juin 2019

Overload C Macros with 1,2 arguments

Not complicated way to overload MACROS with null,one,two arguments

based on this comment I want to overload one/two arguments and if possible 0 argument, but with minimal rows of macros.

Now I did in the following mode

#define GET_MACRO(_1,_2, NAME,...) NAME
#define FOO(...) GET_MACRO(__VA_ARGS__, FOO2, FOO1)(__VA_ARGS__)
#define FOO1(x) ABC(F(x))
#define FOO2(x,y) ABC(F(x), F(y))

FOO(x)  ->  ABC(F(x))

but I have two questions
1) is it possible to do this with less then 4 rows ?
2) is it possible to make overload for 0 arg in the following mode FOO() -> ABC()

Aucun commentaire:

Enregistrer un commentaire