With the new C99 standard, it is possible to write macros with a variable number of arguments ("variadic"), just like it is possible to write such functions. This is especially useful for wrapping variadic functions in macros.

The syntax used is an ellipsis in in the argument list. The string __VA_ARGS__ in the expansion is replaced with the arguments.

As an example, the ubiquitous eprintf macro:

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

which could be invoked like

eprintf("error %d occured in %s\n", error_no, module);

Log in or register to write something here or to contact authors.