tags:

views:

101

answers:

4

I like to compile my code with -Wall, and sometimes even -pedantic. It's partly a style thing, and partly the fact that it does occasionally emit very, very useful warnings (such as using = rather than ==).

However, the writers of some of my headers are clearly not such sticklers. Compiling with either of the two warning levels yields a tremendous mess of output, completely defeating the purpose of compiling that way in the first place.

So how can I make my compiler ignore those warnings?

A: 

Use an appropriate #pragma to disable warnings before you include the bad headers, then re-enable the warnings afterwards. Docs on the GCC pragmas.

JSBangs
A: 

It seems like they're "your" headers, meaning you can modify them yourself or let the "writers" do it for you. If you want to pursue a warning free life, get those headers fixed :).

Alternatively you can of course use pragma's, but they are anti-style and ugly :)

rubenvb
+2  A: 

When invoking GCC, using -isystem instead of -I to give the paths to your problematic headers should silence warnings for those headers. See the GCC docs or this SO question.

Josh Kelley
+5  A: 

Alternatively to JS Bangs' answer, you can have GCC treat them as system headers, which disables all warnings (excepting #warning directives) for those headers.

If the -isystem switch is unhelpful, you can wrap all of the offending headers with simpler headers that contain only the appropriate line:

#pragma GCC system_header
greyfade