warning C4018: '<' : signed/unsigned mismatch [closed]

The compiler is saying that comparing an unsigned variable against a signed variable is –not allowed considered bad practice. This is because of two’s complement representation of a signed variable.

  • (unsigned short) 0xFFFF is 65535, and
  • (short) 0xFFFF is -1.

They both have same the in-memory representation but mean totally opposite things. So the compiler is protecting you from yourself.

The details on this warning can be found at http://msdn.microsoft.com/en-us/library/y92ktdf2.aspx

Leave a Comment