https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121665
Bug ID: 121665
Summary: __VA_COUNT__: Count number of variadic arguments in a
variadic macro
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
Hi!
While you can do this already with macro trickery, it requires some very
unreadable code. I'd like to be able to extract that information directly in a
way similar to how __VA_OPT__() works.
#define foo(a, b, ...) __VA_COUNT__
foo(a, b, c, d)
The code above would expand to
2
Another example:
#define bar(...) __VA_COUNT__
bar() // 0
bar(x) // 1
Could this be added as a GNU extension?
Clang seems to be okay with it, and wants to agree with GCC.