|
|
|
|
|
by raible
45 days ago
|
|
I use something like this to turn __VA_ARGS__ into count/pointer: // Create a stack-allocated argv from N args gcc, clang, tcc, mingw, msvc, etc
// argc is always correct, for portability argv has a dummy element when argc==0
// This avoids problematic 0-length compound literal arrays.
#define _ARG_CV(type, ...) _ARG_CV1(((type []){0, __VA_ARGS__}))
#define _ARG_CV1(array) _ALEN(array) - 1, array + (_ALEN(array) > 1)
#define _ALEN(array) sizeof array / sizeof *array
Then it's just: #define sum(...) sum(_ARG_CV(int, __VA_ARGS__))
|
|
Your version expands `sum(1, 2, 3, 4, 5, 6)` to:
whereas with __VA_COUNT__ it is just: