|
![]() Click on image to see enlargment |
|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home bug650.cpp
A football analyst wanted to print out the names of football teams, blank-separated, four to a line. What could go wrong with such a simple program? bug650.cpp lint Output
--- Module: bug650.cpp (C++)
_
if( i % 4 == 4 ) printf( "\n" );
bug650.cpp(18) : Warning 650: Constant '4' out of range for operator '=='
--- Global Wrap-up
Info 843: Variable 'teams' (line 3, file bug650.cpp) could be declared as const
Reference Manual Explanation
650 Constant out of range for operator String -- In a comparison
operator or equality test (or implied equality test as for a case
statement), a constant operand is not in the range specified by
the other operand. For example, if 300 is compared against a
char variable, this warning will be issued. Moreover, if char is
signed (and 8 bits) you will get this message if you compare
against an integer greater than 127. The problem can be fixed
with a cast. For example:
if( ch == 0xFF ) ...
if( (unsigned char) ch == 0xFF ) ...
If char is signed (+fcu has not been set) the first receives a
warning and can never succeed. The second suppresses the warning
and corrects the bug.
PC-lint/FlexeLint will take into account the limited precision of
some operands such as bit-fields and enumerated types. Also,
PC-lint/FlexeLint will take advantage of some computations that
limit the precision of an operand. For example,
if( (n & 0xFF) >> 4 == 16 ) ...
will receive this warning because the left-hand side is limited
to 4 bits of precision.
If you have comments or questions about this bug, please post them to our Discussion Forum |
Previous Bug - Bug #444 - September 2009