__VA_ARGS__ is a predefined C preprocessor identifier used inside a variadic macro. It expands to the arguments supplied after the named parameters and the ellipsis (...), preserving the comma-separated argument list. For example, TRACE_PRINT6("a collection: %g, %i", sum, argc) can forward sum and argc through __VA_ARGS__ to fprintf. section 17.4.1
Forwarding variadic arguments
#define TRACE_PRINT(FORMAT, ...) \ fprintf(stderr, FORMAT, __VA_ARGS__) TRACE_PRINT("value: %i\n", 42) Here, __VA_ARGS__ expands to 42, producing a call equivalent to fprintf(stderr, "value: %i\n", 42). The macro requires at least one variadic argument: if the list is absent, the resulting fprintf call contains an invalid empty argument after FORMAT. section 17.4.1
Use __VA_ARGS__ with these constraints and extensions:
- Combine __VA_ARGS__ with C23 __VA_OPT__(,) when the separating comma must appear only for a nonempty variadic list. section 17.4.1
- Stringify __VA_ARGS__ like another macro parameter; the resulting text includes commas separating the supplied arguments. section 17.4.1
- Forward arbitrary initialization arguments through a type-specific macro such as P99_NEW(T, ...), where __VA_ARGS__ supplies the arguments to T_init. section 13.4
- Use __VA_ARGS__ in dispatch patterns that select macro variants according to whether optional arguments are present. section 17.4.1 section 17.5
