Our programmer is summing up an array whose termination is signalled by a special sentinel. However it's taking a lot longer than anticipated. What's the problem?
bug685.cpp lint Output
--- Module: bug685.cpp _ while( (*p & 0xFF) <= 255 ) bug685.cpp(9) : Warning 685: Relational operator '<=' always evaluates to 'true' _ } bug685.cpp(14) : Info 818: Pointer parameter 'p' (line 5) could be declared as pointing to const
Reference Manual Explanation
685 Relational operator 'String,' always evaluates to 'String' -- The first String is one of '>', '>=', '<' or '<=' and identifies the relational operator. The second string is one of 'True' or 'False'. The message is given when an expression is compared to a constant and the precision of the expression indicates that the test will always succeed or always fail. For example, char ch; ... if( ch >= -128 ) ... In this example, the precision of char ch is 8 bits signed (assuming the fcu flag has been left in the OFF state) and hence it has a range of values from -128 to 127 inclusive. Hence the test is always True. Note that, technically, ch is promoted to int before comparing with the constant. For the purpose of this comparison we consider only the underlying precision. As another example, if u is an unsigned int then if( (u & 0xFF) > 0xFF ) ... will also raise message 685 because the expression on the left hand side has an effective precision of 16 bits.
If you have comments or questions about this bug, please post them to our Discussion Forum
Previous Bug - Bug #684 - July 2002