Skip to content

__VA_COUNT__: Count number of variadic arguments in a variadic macro #155234

@alejandro-colomar

Description

@alejandro-colomar

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
#define bar(...)  __VA_COUNT__

bar()  // 0
bar(x)  // 1

Could this be added as a Clang extension?

Cc: @AaronBallman

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions