Click on image to see enlargment
A florist who knows flowers better than programming is automating his shop, but there seems to be a problem with the printout of bridal bouquets. Somehow the baby's breath is always missing. What's going on?
bug571.cpp lint Output
--- Module: bug571.cpp (C++) _ switch( (unsigned) ch ) bug571.cpp(6) : Warning 571: Suspicious cast
Reference Manual Explanation
571 Suspicious Cast -- Usually this warning is issued for casts of the form: (unsigned) ch where ch is declared as char and char is signed. Although the cast may appear to prevent sign extension of ch, it does not. Following the normal promotion rules of C, ch is first converted to int which extends the sign and only then is the quantity cast to unsigned. To suppress sign extension you may use: (unsigned char) ch Otherwise, if sign extension is what you want and you just want to suppress the warning in this instance you may use: (unsigned) (int) ch Although these examples have been given in terms of casting a char they will also be given whenever this cast is made upon a signed quantity whose size is less than the casted type. Examples include signed bit fields (a possibility in the new standard), expressions involving char, and expressions involving short when this type is smaller than int or a direct cast of an int to an unsigned long (if int is smaller than long). This message is not issued for constants or for expressions involving bit operations.
If you have comments or questions about this bug, please post them to our Discussion Forum
Previous Bug - Bug #794 - April 2008