Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily disable gcc warning on redefinition

I'm trying to make this work (in GCC 4.6) without barking at me.

#define FOO  "" #define BAR  ""  #if ....     #define FOO    "Foo, good sir" #endif  #if ...     #define BAR    "Bar, my lady" #endif ....  #define EVERYTHING      FOO BAR ... 

I am going to have a lot of these. So doing it that way instead of:

#if ...     #define FOO    "Foo" #else     #define FOO    "" #endif 

Saves a lot of code, and makes it more readable. The warning that I get is:

warning: "FOO" redefined [enabled by default]

Is there a way to disable this warning in the code for this particular section? I found Diagnostic Pragmas to disable certain warnings, but I'm not able to find which warning (in this list of Options to Request or Suppress Warnings) that needs to be disabled here.

Anyone know how to do this? Or a different way to avoid having to #else #define all of them to the empty string?

like image 801
Jonathon Reinhart Avatar asked Nov 16 '11 23:11

Jonathon Reinhart


People also ask

How do I turn off GCC warnings?

The warning message for each controllable warning includes the option that controls the warning. That option can then be used with -Werror= and -Wno-error= as described above. (Printing of the option in the warning message can be disabled using the -fno-diagnostics-show-option flag.)

How do I turn off error warning?

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).

How do I ignore a warning in Makefile?

Maybe you can look for CFLAGS options in Makefile and remove the -Werror flag. The Werror flag will make all warnings into errors.

How does GCC treat warning errors?

You can use the -Werror compiler flag to turn all or some warnings into errors. Show activity on this post. You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.


1 Answers

Try using #undef:

#define FOO ""  #if ....     #undef FOO     #define FOO "Foo, good sir" #endif 
like image 149
Greg Hewgill Avatar answered Oct 24 '22 12:10

Greg Hewgill