Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warnings in third-party source files?

Tags:

c++

c

gcc

eclipse

keil

I am familiar with warning suppressing pragmas for GCC and Keil (they are different, but the usage is pretty much the same). For a third-party headers I can do something like this:

#pragma push
#pragma suppress warning
#include "whatever.h"
#pragma pop

But how can I suppress warnings from third-party sources? Both Eclipse+GCC and Keil generate them. The only solution I came up is making whapper .c-file, which will include other .c files, which seems to be very dirty trick.

Are there any other solutions?

like image 481
Amomum Avatar asked Aug 30 '13 10:08

Amomum


People also ask

How do you suppress a warning?

If we don't want to fix the warning, then we can suppress it with the @SuppressWarnings annotation. This annotation allows us to say which kinds of warnings to ignore. While warning types can vary by compiler vendor, the two most common are deprecation and unchecked.

How do I disable a specific warning in Visual Studio?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.

How do I supress a warning in GCC?

-Wno-coverage-mismatch can be used to disable the warning or -Wno-error=coverage-mismatch can be used to disable the error. Disabling the error for this warning can result in poorly optimized code and is useful only in the case of very minor changes such as bug fixes to an existing code-base.

How do I ignore warnings in C#?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.


2 Answers

with gcc , while compiling you can use -w option to suppress warnings.

-w : Inhibit all warning messages.

Example:

gcc -w third_party_sourcefile.c 
like image 144
Gangadhar Avatar answered Oct 24 '22 22:10

Gangadhar


You may want to use -isystem instead of -Idir third party headers. See GCC manual.

If you're ok to edit third party source files, you can use #pragma GCC diagnostic ignored "-Wwarning-to-disable" see GCC manual.

like image 26
Gregory Pakosz Avatar answered Oct 24 '22 23:10

Gregory Pakosz