Variable Argument Macros

When the C99 extensions setting is on, the compiler allows macros to have a variable number of arguments. The following listing shows an example.

Listing: Variable argument macros example

#define MYLOG(...) fprintf(myfile, __VA_ARGS__)

#define MYVERSION 1

#define MYNAME "SockSorter"

int main(void)

{

    MYLOG("%d %s\n", MYVERSION, MYNAME);

    /* Expands to: fprintf(myfile, "%d %s\n", 1, "SockSorter"); */

    return 0;

}