6

这个 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
4

3 回答 3

8

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

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

然后你也会避免, ##构造的 gcc 扩展。

于 2010-07-31T14:56:42.383 回答
1

我的 SNAP_LISTEN(...) 宏遇到了类似的问题(尽管在 C++ 中),定义如下。我找到的唯一解决方案是创建一个不包含 args... 参数的新宏 SNAP_LISTEN0(...)。在我的情况下,我没有看到另一种解决方案。-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
于 2012-10-14T07:31:17.830 回答
1

这意味着您没有将第二个参数传递给 log_debug。它期望该部分有一个或多个参数...,但您传递的参数为零。

于 2010-07-31T14:43:22.900 回答