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

时间:2010-07-31 14:33:44

标签: c gcc c99 variadic

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

3 个答案:

答案 0 :(得分:8)

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

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

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

我遇到了类似的问题(尽管在C ++中),我的SNAP_LISTEN(...)宏定义如下。我找到的唯一解决方案是创建一个新的宏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