When running cl.exe
, you can specify the warning level.
cl /W3
cl /W4 # warn even more
cl /Wall # all warn开发者_开发百科ings on
However, the highest level, /Wall
, seems impractical because it triggers warnings in Windows header files, such as in windef.h
(Windows SDK for VS2010). The two most frequently occurring ones seem to be C4668 and C4820. So you can switch them off:
cl /Wall /wd4668 /wd4820
Still leaves you with C4255:
C:\SDKs\Windows\v7.0A\include\windef.h(230) : warning C4255: 'FARPROC'
C:\SDKs\Windows\v7.0A\include\windef.h(231) : warning C4255: 'NEARPROC'
C:\SDKs\Windows\v7.0A\include\windef.h(232) : warning C4255: 'PROC'
So you add that as well:
cl /Wall /wd4668 /wd4820 /wd4255
But others might crop up. And I might want to keep those warnings for my own code, just not have the output cluttered by warnings which did not originate in my code.
Is there a way to make the compiler apply different settings to standard headers than to my own code?
Update
Hmm, there's a similar question, and the answer is to go with /W4
instead of /Wall
. Maybe it's not possible with MSVC to specify different settings for different files.
Unfortunately, Visual Studio doesn't seem to have an option to specify warning levels for all header files found in a specific search path or something similar to turn off the warnings. I myself just stick with /W4
because of the exact problem you're describing.
The only way I can think of to get around this is to use the following in all your files wherever the offending headers are included:
#pragma warning( push, 4 ) // Saves the current warning level and sets it to 4
#include <Windows.h>
#pragma warning( pop ) // Restores the old warning level
#include "MyHeader.h" // Include other 'non-system' headers
Note that I haven't actually tried this, so it may not work at all!
精彩评论