由 `-pedantic` 生成的编译器警告是什么意思?
GCC 警告是什么意思?
cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used
相关行是:
__attribute__((format(printf, 2, 3)))
static void cpfs_log(log_t level, char const *fmt, ...);
#define log_debug(fmt, ...) cpfs_log(DEBUG, fmt, ##__VA_ARGS__)
log_debug("Resetting bitmap");
最后一行是函数实现中的第 232 行。编译器标志是:
-g -Wall -std=gnu99 -Wfloat-equal -Wuninitialized -Winit-self -pedantic
What does this GCC warning mean?
cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used
The relevant lines are:
__attribute__((format(printf, 2, 3)))
static void cpfs_log(log_t level, char const *fmt, ...);
#define log_debug(fmt, ...) cpfs_log(DEBUG, fmt, ##__VA_ARGS__)
log_debug("Resetting bitmap");
The last line being line 232 inside a function implementation. The compiler flags are:
-g -Wall -std=gnu99 -Wfloat-equal -Wuninitialized -Winit-self -pedantic
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这意味着您必须按照定义的方式传递至少两个参数。您可以这样做
,然后您还可以避免
, ##
构造的 gcc 扩展。Yes it means that you have to pass at least two arguments the way that you defined it. You could just do
and then you'd also avoid the gcc extension of the
, ##
construct.这意味着您没有将第二个参数传递给 log_debug。它期望
...
部分有一个或多个参数,但您传递的是零。It means that you are not passing a second argument to log_debug. It's expecting one or more arguments for the
...
part, but you're passing zero.我的 SNAP_LISTEN(...) 宏也有类似的问题(尽管是在 C++ 中),如下定义。我找到的唯一解决方案是创建一个新的宏 SNAP_LISTEN0(...) ,它不包含 args... 参数。在我的案例中,我没有看到其他解决方案。 -Wno-variadic-macros 命令行选项可以防止可变参数警告,但不能防止 ISO C99 警告!
编辑:编译器版本
编辑:命令行警告
-Wno-variadic-macros 本身可以工作,因为我没有收到一条错误消息说不接受可变参数。但是,我遇到了与 Matt Joiner 相同的错误:
I am having a similar problem (although in C++) with my SNAP_LISTEN(...) macro as defined below. The only solution I have found is to create a new macro SNAP_LISTEN0(...) which does not include the args... parameter. I do not see another solution in my case. The -Wno-variadic-macros command line option prevents the variadic warning but not the ISO C99 one!
Edit: compiler version
Edit: command line warnings
The -Wno-variadic-macros itself works since I do not get an error saying that the variadic is not accepted. However, I get the same error as Matt Joiner: