Code version 2 of the GNU General Public License the Creative Commons Attribution-ShareAlike 3.0 License

GCC 4.3 now gives errors on certain problems with variadic macros. First, it’s important to know what a variadic macro is. C has allowed macros as long as it’s been around. But C99 introduced a new feature called variadic macros. Like a variadic function, which takes a variable number of arguments (printf is a good example), a variadic macro can take a variable number of arguments. The standard form of this is:

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

This takes whatever arguments are given to varfunc and replaces __VA_ARGS__ with them. There’s also a GCC extension that uses a named parameter instead:

#define varfunc(args...) fprintf(stderr, args)

In this case, whatever name is used before the ellipsis (in this case, args) is used instead of the __VA_ARGS__ macro.

Note that these macros may only work in C99 or C++0x, because they rely on newer features of the preprocessor. And since the latter is a GCC extension, the former is a better choice, unless you’re using an old version of GCC.