Problem introduction:
In order to use macro definitions to transform the printf function so that it can print out more information, the following macro definitions are defined:
#define debug(fmt, ...) printf("%s->%d: "fmt, __func__, __LINE__, ##__VA_ARGS__)
The problem arises:
When using macros in code debug
, the gcc compiler issues an error message:
error: ISO C99 requires at least one argument for the "..." in a variadic macro [-Werror]
Solution:
Check CFLAGS
the compilation options, use -Wno-variadic-macros
or -pedantic
remove them.
Other ways to use
GCC has long supported variadic macros, with a different syntax that allowed you to give variadic parameters names like any other parameter. Here's an example:
#define debug(format, args...) fprintf (stderr, "%s->%d: "format, __FILE__, __LINE__, args)