Comment by raible
6 hours 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__))
No comments yet
Contribute on Hacker News ↗