2010-07-31 71 views
6

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

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 

回答

8

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

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

,然后你想也避免, ##结构的GCC扩展。

+1

这让我困惑了很长一段时间。实际上标准的方法是'log_debug(“%s”,“重置位图”);'。 – Dummy00001 2010-07-31 15:50:29

+0

预处理器省略号替代一个或多个参数有多奇怪,但C省略号替代零个或更多。我在从C99标准中提取这种语义时遇到了一些麻烦。 – 2012-11-23 02:19:53

1

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

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-可变参数的宏本身的工作,因为我没有得到一个错误,指出一个可变不被接受。然而,我得到了同样的错误作为马特乔伊纳:

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

什么版本的GCC,以及在编译过程中指定了哪些C++修订版本? – 2012-10-14 10:04:02

+0

由于我使用了很多-W命令行选项,因此我对答案进行了更新。 – 2012-10-19 06:23:32

相关问题