Click on image to see enlargment
A programmer wrote int_check(k) to determine some of the properties of its integer argument. But there's a slight flaw. Can you spot it?
bug845.cpp lint Output
--- Module: bug845.cpp (C++) _ else if( k == 0 ) p &= ZERO; bug845.cpp 10 Info 845: The left argument to operator '&' is certain to be 0 [Reference: file bug845.cpp: line 8]
Reference Manual Explanation
845 The [left/right] argument to operator 'Name' is certain to be 0 -- An operand that can be deduced to always be 0 has been presented to an arithmetic operator in a context that arouses suspicion. The name of the operator is provided in the message as well as the side of the operator (left or right) that had the unusual value. For example: n = 0; k = m & n; will produce a message that the right hand operand of operator '&' is certain to be zero. The operands examined are the right hand sides of operators + - | || the left hand sides of operators / % and both sides of operators * & << >> && The reason that the left hand side of operator + (and friends) is not examined for zero is that zero is the identity operation for those operators and hence is often used as an initializing value. For example: sum = 0; for( ... ) sum = sum + what_ever; // OK, no message The message is not issued for arithmetic constant zeros. Info 835 in Section 13.4 is issued in that instance. The message is also suspended when the expression has side-effects. For example: i = 0; buf[i++] = 'A'; We don't consider it reasonable to force the programmer to write: buf = 'A'; i = 1;
If you have comments or questions about this bug, please post them to our Discussion Forum
Previous Bug - Bug #616 - April 2010