Visual Studio signed/unsigned Comparison Warnings

I use Visual Studio 2005 for my Chromium builds.  Because Chromium is a cross-platform product (Windows, Mac, and Linux), we’ve built tools (robots) which can automatically build our code changes on the other platforms before we ever commit the change.  When a pending change fails on the robots for other platforms, it creates a headache for me because I have to rework the patch and retest.

Unfortunately, on Windows we use warning level 3, which treats Visual Studio warning 4018 as a problem but not Visual Studio warning 4389.  4018 treats signed and unsigned comparisons for greater-than or less-than as warnings, but not equality comparisons.  4389 treats signed and unsigned equality comparisons as warnings.  Why Microsoft split these into two different warnings, I don’t know.  They should be part of a single warning, in my opinion.

g++, which we use on Linux and Mac builds, does not differentiate these signed/unsigned comparisons in the same way.  And this is annoying, because it means that a signed/unsigned equality comparison will seem to work on my Windows machine, and then fail on Linux and Mac (“warning: comparison between signed and unsigned integer expressions”!).

If you have a similar problem, I recommend using Visual Studio’s option for “/we4389”, which will include warning 4389.  And alas – your builds on all platforms will treat unsigned/signed comparisons the same way.  Phew!

Leave a Reply

Your email address will not be published. Required fields are marked *