How to make a variadic macro (variable number of arguments)

cc-preprocessorg++variadic

I want to write a macro in C that accepts any number of parameters, not a specific number

example:

#define macro( X )  something_complicated( whatever( X ) )

where X is any number of parameters

I need this because whatever is overloaded and can be called with 2 or 4 parameters.

I tried defining the macro twice, but the second definition overwrote the first one!

The compiler I'm working with is g++ (more specifically, mingw)

Best Answer

C99 way, also supported by VC++ compiler.

#define FOO(fmt, ...) printf(fmt, ##__VA_ARGS__)