views:

706

answers:

5

I would like to have my warnings set to the highest level using Microsoft Visual C++ compiler. Similar to using -pedantic on gcc. What compiler switches do you use to have the most warnings enabled?

+1  A: 

/W4 /Wall should do the trick.

Menkboy
+7  A: 

The highest warning level on Visual C++ is /Wall. The warning level can also be set numerically with /W0, /W1, ... /W4 to generate increasing levels of warnings.

The compiler will also check for 64 bit portability issues with /Wp64.

And you can tell it to treat warnings as errors with /WX

Visual C++ doesn't seem to have an real equivalent to -pedantic - which is asking gcc to report all warnings required to be reported by the ISO C and C++ standards.

billmcc
+2  A: 

Note that /Wp64 is not recommended by Microsoft as opposed to compiling directly for the 64-bit platform if possible.

Also note that the Team Developer edition has a /analyze option, which adds semantic checking for common code errors. You can also look at getting PC-lint from gimpel for additional semantic checking.

Nick
The correct information is that where possible compiling directly for the 64-bit platform is preferable to using the /Wp64 option.
Andrew Grant
Yes; more specifically /Wp64 can give erroneous warnings and not give appropriate warnings compared to compiling directly for 64-bit.
Nick
The fun part is that compiling for 64-bit without /Wp64 will let you truncate pointers left and right without getting any warnings.
bk1e
The boring part is that compiling for 32-bit with /Wp64 will give you warnings even when you do what you should, e.g. use GetWindowLongPtr() and cast the result to a ptr...
Andreas Magnusson
+3  A: 

AS billmcc64 mentioned, gcc's -pedantic causes gcc to warn if you use any non-standard extensions. I don't think you can get MSVC to warn for a similar situation, but you can cause it to generate an error for these situations using the /Za option.

Michael Burr
+2  A: 

if you want something like -pedantic, try a good lint like pc-lint (http://www.gimpel.com/html/products.htm).

Ray Tayek