6

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
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

3 Answers3

8

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.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
  • 1
    That puzzled me for quite some time too. Actually standard way would be `log_debug("%s", "Resetting bitmap");`. – Dummy00001 Jul 31 '10 at 15:50
  • How odd that the preprocessor ellipsis substitutes for one or more arguments, yet the C ellipsis substitutes for zero or more. I'm having some trouble extracting this semantic from the C99 standard. – Martin Dorey Nov 23 '12 at 02:19
1

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
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
1

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.

Douglas
  • 36,802
  • 9
  • 76
  • 89