c/c++
Counting variadic arguments
Submitted by moonz on Fri, 2010-07-16 19:08The following code is simplified version of a code snippet which I’ve found on stack overflow site.
#define VA_COUNT(…) VA_COUNT0(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#define VA_COUNT0(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, …) N
#define VA_COUNT0(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, …) N
Being able to count at preprocessing stage, means many things.
There’re a bunch of subtle, dirty expressions related to variadic macro or function in C.