views:

241

answers:

2

I'm starting a new BREW project, and I'd like to compile with Warning Level 4 (/W4) to keep the application code nice and clean. The problem is that the BREW headers themselves don't compile cleanly with /W4.

In gcc you can differentiate between application and system headers by using -I and -isystem, and then by default gcc doesn't report any compilation warnings in system headers. Is there an equivalent mechanism in Visual C++?

+7  A: 

Only use this method around a block of headers that you cannot change, but that you need to include.

You can selectively, and temporarily disable all warnings like this:

#pragma warning(push, 0)        
//Some includes with unfixable warnings
#pragma warning(pop)

Instead of 0 you can optionally pass in the warning number to disable, so something like:

#pragma warning( push )
#pragma warning( disable : 4081)
#pragma warning( disable : 4706 )
// Some code
#pragma warning( pop ) 
Brian R. Bondy
StackOverflow rocks. Thanks for the complete answer.This solution is relatively annoying because it has to be done correctly in every source file, whereas in gcc you just configure your makefile correctly once.
Bob Whiteman
@Bob: No prob, glad to help. You could try putting those includes inside a different file and putting your include warning disables around just that one file.
Brian R. Bondy
That's not particularly practical for BREW either, because there isn't one single base header file (or small group of header files) to wrap with an intermediate header. A typical project will have many source and header files, each of which includes a different subset of the BREW headers.I could potentially make one super-header that includes ALL BREW headers, and then pre-compile it to keep builds efficient. This technique would only work for Visual C++, and BREW projects need to build with at least two compilers (Visual C++ for simulator builds, and gcc or ARM for handsets).
Bob Whiteman
A: 

I don't believe Visual C++ lets you differentiate. You can fake it by using #pragma warning around the include:

#pragma warning(push, 0)
#include "mywarningheader.h"
#pragma warning(pop)
Dan Story