由 `-pedantic` 生成的编译器警告是什么意思?

发布于 2024-09-12 19:11:23 字数 477 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

书信已泛黄 2024-09-19 19:11:23

是的,这意味着您必须按照定义的方式传递至少两个参数。您可以这样做

#define log_debug(...) cpfs_log(DEBUG, __VA_ARGS__)

,然后您还可以避免 , ## 构造的 gcc 扩展。

Yes it means that you have to pass at least two arguments the way that you defined it. You could just do

#define log_debug(...) cpfs_log(DEBUG, __VA_ARGS__)

and then you'd also avoid the gcc extension of the , ## construct.

因为看清所以看轻 2024-09-19 19:11:23

这意味着您没有将第二个参数传递给 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.

后eg是否自 2024-09-19 19:11:23

我的 SNAP_LISTEN(...) 宏也有类似的问题(尽管是在 C++ 中),如下定义。我找到的唯一解决方案是创建一个新的宏 SNAP_LISTEN0(...) ,它不包含 args... 参数。在我的案例中,我没有看到其他解决方案。 -Wno-variadic-macros 命令行选项可以防止可变参数警告,但不能防止 ISO C99 警告!

#define SNAP_LISTEN(name, emitter_name, emitter_class, signal, args...) \
    if(::snap::plugins::exists(emitter_name)) \
        emitter_class::instance()->signal_listen_##signal( \
            boost::bind(&name::on_##signal, this, ##args));

#define SNAP_LISTEN0(name, emitter_name, emitter_class, signal) \
    if(::snap::plugins::exists(emitter_name)) \
        emitter_class::instance()->signal_listen_##signal( \
            boost::bind(&name::on_##signal, this));

编辑:编译器版本

g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编辑:命令行警告

set(CMAKE_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -std=c++0x
  -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization
  -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept
  -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow
  -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default
  -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses
  -fdiagnostics-show-option")

-Wno-variadic-macros 本身可以工作,因为我没有收到一条错误消息说不接受可变参数。但是,我遇到了与 Matt Joiner 相同的错误:

cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used

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!

#define SNAP_LISTEN(name, emitter_name, emitter_class, signal, args...) \
    if(::snap::plugins::exists(emitter_name)) \
        emitter_class::instance()->signal_listen_##signal( \
            boost::bind(&name::on_##signal, this, ##args));

#define SNAP_LISTEN0(name, emitter_name, emitter_class, signal) \
    if(::snap::plugins::exists(emitter_name)) \
        emitter_class::instance()->signal_listen_##signal( \
            boost::bind(&name::on_##signal, this));

Edit: compiler version

g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Edit: command line warnings

set(CMAKE_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -std=c++0x
  -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization
  -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept
  -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow
  -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default
  -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses
  -fdiagnostics-show-option")

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:

cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文