3 ms·
c99 makes this much, much easier than they think: #define ARG_16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,...) q #define COUNT(...) ARG_16(x,##__VA_ARGS__,15,14
by aidenn0 15y ago
c99 makes this much, much easier than they think:
#define ARG_16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,...) q
#define COUNT(...) ARG_16(x,##__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
#define PASTE2(a,b) a ## b
#define CALLFN(name,nargs,...) PASTE2(name,nargs)(__VA_ARGS__)
#define FOO(...) CALLFN(foo,COUNT(__VA_ARGS__),__VA_ARGS__)
- LefterisJP 15y agoAs I told you inside the comments in the blog itself, what is x in the definition of COUNT(...) ? Also it seems that you did not read the topic correctly because even if you tried to apply such a method it would fail for the no arguments case, which is a big part of the bulk of the first method. If I don't get something please feel free to explain