Click on image to see enlargment
Temperature readings from Point Barrow, Alaska, give an unusually high value for the average temperature in March. Try as they might they could not attribute this to global warming. Could the bits and bytes be frozen? What's going on?
bug573.cpp lint Output
--- Module: bug573.cpp (C++) _ " %d degrees\n", sum / count ); bug573.cpp(18) : Warning 573: Signed-unsigned mix with divide bug573.cpp(18) : Info 737: Loss of sign in promotion from int to unsigned int
Reference Manual Explanation
573 Signed-unsigned mix with divide -- one of the operands to / or % was signed and the other unsigned; moreover the signed quantity could be negative. For example: u / n where u is unsigned and n is signed will elicit this message whereas: u / 4 will not, even though 4 is nominally an int. It is not a good idea to mix unsigned quantities with signed quantities in any case (a 737 will also be issued) but, with division, a negative value can create havoc. For example, the innocent looking: n = n / u will, if n is -2 and u is 2, not assign -1 to n but will assign some very large value. To resolve this problem, either cast the integer to unsigned if you know it can never be less than zero or cast the unsigned to an integer if you know it can never exceed the maximum integer.
If you have comments or questions about this bug, please post them to our Discussion Forum
Previous Bug - Bug #1506 - February 2007