Warnings considered useful

As stated before, I’m a big fan of oversensitive warnings and try to compile my projects with the highest warning level (/W4) under MSVC. However, as it turns out, even at this level there are still warnings that are not enabled. For a complete list of warnings that are off by default, see here. The easiest way to enable them all is to use /Wall switch, but it’s too much even for me (mainly because of C4820, feel free to give it a try, though). Below you can find a list of warnings I consider helpful and have enabled in my projects.

  • C4062 - the enumerate has no associated handler in a switch statement, and there is no default label. C4061 is overkill IMO (same, but doesn’t check for **default **label).

  • C4263 - a class function definition has the same name as a virtual function in a base class but not the same number or type of arguments. This effectively hides the virtual function in the base class. There are rare cases when this may be intentional, usually it’s just a typo.

  • C4265 - class has virtual functions, but destructor is not virtual. It puzzles me it’s off by default.

  • C4431 - missing type specifier - int assumed.

  • C4545 - C4549 - ill formed comma expressions, skip C4548, it tends to go off on standard headers.

  • C4710 - function not inlined. Enable optionally for a quick overview.

Most of those warnings shouldnt trigger on typical code base, but that’s even better reason to enable them. One day they may save you an hour or two of debugging. Complete list is much longer, check it out and you may find some other useful warnings for your application. Use /Za (ANSI compatibility) for double-hit combo (sadly it’s incompatible with /fp:fast and it’s virtually impossible to compile anything including Windows header in this mode).

PS. As you may have heard - C&C: Tiberium has been cancelled. While I wasn’t really that hooked on the title itself, it’s the reaction that’s most interesting here. Just read comments under Gamasutra article. As someone put it there, it may as well be “EA Spouse” of 2008. Regional bonus: Polish readers should find some familiar situations as well, search for comments by Jacek Wesolowski and play the “name the company/people” game with your industry buddies.

Old comments

ed 2008-10-04 20:29:37

Weird indeed. Many of those seems to be pretty useful (except C4061 :) ). Recently I have also found weird behavior of the MSVC. There was a obvious divide by zero “#define VAL 0”, “int a = counter / VAL;” and compiler didn’t gave any warnings. What was more strange, I’ve found out about this, after I’ve turned on “Whole Program Optimization” and linker gave me a warning.
@PS: I loved the comment “At MobyGames resumes, you’ll find Andre Garcia, a QA tester for nearly a decade, quickly went from nothing, to a design lead position”… that sounds familiar… where did I saw that ? .. Ah yes… :) Seems like one of the polish companies copies “what’s the best EA has to offer”.

js 2008-10-06 08:07:00

Gamasutra’s comments make me think of a Vendetta. A place for blood and revenge…

[…] Warnings considered useful I like maximum warnings when using compiled code because it helps to weed out the idiocies of programming, and this developer gives Windows developers some good pointers. […]

Jacek Weso??owski 2008-10-08 01:21:08

I hope I didn’t mess up too many details. It all happened some time ago, and the memory inhibition mechanism is starting to kick in. Treat it as a fairy tale rather than accurate report.
I would also like to point out that in the latest “Du??y Lotek” lottery I hit 1 of 6 and 0 of 6.

Older, Not Wiser « What Makes You Think I’m Not 2008-11-12 22:28:32

[…] sort of a compiler warning week, I guess. Anyway, I noticed over here at .mischief.mayhem.soap that there’s actually a /Wall for Visual Studio. It’s not in the UI, but you can turn […]

More Reading