Table of Contents
Previous Section Next Section

C99 Variable Argument Lists

C99 adds to the preprocessor the ability to create macros that take a variable number of arguments. This is indicated by an ellipsis (. . .) in the definition of the macro. The built-in preprocessing identifier _ _VA_ARGS_ _ determines where the arguments will be substituted. For example, given this definition,

#define MyMax(...) max(_ _VA_ARGS_ _)

this statement

MyMax(a, b);

is transformed into

max(a, b);

There can be other arguments prior to the variable ones. For example, given

#define compare(compfunc, ...) compfunc(_ _VA_ARGS_ _)

this statement

compare(strcmp, "one", "two");

is transformed into

strcmp("one", "two");

As the example shows, _ _VA_ARGS_ _ is replaced by all of the remaining arguments.


Table of Contents
Previous Section Next Section