https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33877
--- Comment #6 from Alejandro Colomar <foss+...@alejandro-colomar.es> --- (In reply to Michael FIG from comment #0) > It would be really convenient if the C preprocessor exposed the number of > variable arguments supplied to a variadic macro as an integer. I tried to > come up with ways of working around this missing feature, but I can't figure > out how to do it without evaluating the macro arguments twice or causing > compiler warnings. > > I can supply a patch, if I am blessed with my proposed solution, to have > __VA_ARGC__ be an integer count of the number of __VA_ARGS__. If you have > suggestions for a better design, I'd like to hear them! > > Thanks, > Michael. Please make sure to differentiate correctly the case of 0 and 1 arguments. #define foo(...) __VA_ARGC__ #define bar(a, ...) __VA_ARGC__ foo() // 0 foo(x) // 1 foo(,) // 2 bar(a) // 0 bar(a,) // 1 bar(a,b) // 1