Regarding the solution to error: ISO C99 requires at least one argument for the “...“ in a variadic macro [-Werror]

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 CFLAGSthe compilation options, use -Wno-variadic-macrosor -pedanticremove 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)

Reference: gcc 'ISO C99 requires "..." in variadic macros to have at least one argument' specifically when using c11 and -Wno-varidic-macros [duplicate]

Guess you like

Origin blog.csdn.net/weixin_40837318/article/details/130199484