Question

We're doing some code cleanup, fixing signed/unsigned comparisons, running static analysis, etc, on the code base of C, C++, and Java.

One of the warnings we're getting is

warning: ISO C does not permit named variadic macros

And its companion warning

warning: ISO C99 requires rest arguments to be used

Now, in the C code I used the C99 standard variadic macro to fix the problem, but in the C++ code, what is the correct answer? Using the same C99 style results in a different warning

warning: anonymous variadic macros were introduced in C99 

For which I don't see any answers.

We're using GCC (G++) 4.4.3 in Linux.

I'm hoping there is some flag, or other method that can correct, or disable it for the specific section of code - but its for the logging which is used in almost every file...

Was it helpful?

Solution

Use the gcc option -Wno-variadic-macros to disable that particular warning.

Edit: (from comments)

To disable the warning for a section of code but leave it on in general, use #pragma GCC diagnostic described here.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros"

    // Your code and/or include files
    // (No variadic warnings here)

#pragma GCC diagnostic pop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top