Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable #warning just for one header

In C/C++ code I try to port, a deprecated system header is included:

From the header:

#ifdef __GNUC__
#warning "this header is deprecated"
#endif

As we compile here with gcc -Wall -Werror, compilation stops. In the long run, replacing the use of deprecated functions is best, but for now I want to disable just this warning.

Compiling without -Werror of course works, but as this is part of a completely automated build process, I prefer not to do that.

Including the header with #undefing __GNUC__ before and #defineing it afterwards is a possibility, but I'm worried of the side effects inside the included header.

Is there a way to either disable #warning or relax -Werror just for one header?

like image 363
Thomas Erker Avatar asked Sep 10 '15 11:09

Thomas Erker


People also ask

What does being disable mean?

1 : impaired or limited by a physical, mental, cognitive, or developmental condition : affected by disability. 2 : incapacitated by illness, injury, or wounds. disabled.

Does disable mean turn off?

To disable is defined as to make something not work that was working before, or to injure someone in a way that makes them unable to do something. An example of disable is to stop a car from running by disconnecting the battery cables.

What is the noun form of disable?

—disablement noun [countable, uncountable] —disabling adjective a disabling injury→ See Verb tableExamples from the Corpusdisable• Don had been permanently disabled in a car accident.

What Diable means?

highly spiced; prepared with hot or piquant seasoning; deviled.


1 Answers

You can do this with a (GCC specific) diagnostic pragma

If you surround the include with the following it will disable any warnings caused by #warning.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include "header.h"
#pragma GCC diagnostic pop

Note that if you change the ignored to warning in the above the compiler still prints the warnings - it just doesn't act on the -Werror flag for them.

like image 155
Simon Gibbons Avatar answered Oct 17 '22 02:10

Simon Gibbons