Variadic macros
More complex than object-like macros, a function-like macro definition declares the names of formal parameters within parentheses, separated by commas. An empty formal parameter list is legal: such a macro can be used to simulate a function that takes no arguments. C99 adds support for function-like macros with a variable number of arguments. XL C++ supports function-like macros with a variable number of arguments, as a language extension for compatibility with C and as part of C++11.

Variadic macro extensions refer to two extensions to C99 and C++03 related
to macros with variable number of arguments. One extension is a mechanism for renaming the variable
argument identifier from __VA_ARGS__ to a user-defined identifier. The other
extension provides a way to remove the dangling comma in a variadic macro when no variable arguments
are specified. Both extensions have been implemented to facilitate porting programs developed with
GNU C and C++.
__VA_ARGS__. The first definition of the macro debug exemplifies
the usual usage of __VA_ARGS__. The second definition shows the use of the
identifier args in place of __VA_ARGS__.
#define debug1(format, ...) printf(format, ## __VA_ARGS__)
#define debug2(format, args ...) printf(format, ## args)
| Invocation | Result of macro expansion |
|---|---|
debug1("Hello %s/n", "World"); |
printf("Hello %s/n", "World"); |
debug2("Hello %s/n", "World"); |
printf("Hello %s/n", "World"); |
## precedes the variable argument identifier in
the function macro definition.