|
![]() Click on image to see enlargment |
|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home bug850.cpp
Baltazar, a C++ student, wrote this small program to produce the Nth triangular number. To his dismay he kept getting an unexpected answer. What's wrong? bug850.cpp lint Output
--- Module: bug850.cpp (C++)
_
printf( "%d\n", sum );
bug850.cpp(20) : Info 850: for loop index variable 'i' whose type category is
'integral' is modified in body of the for loop that began at 'line 17'
Reference Manual Explanation
850 for loop index variable 'Symbol' whose type category is 'String'
is modified in body of the for loop that began at 'String' -- Note:
This message is delivered after the for loop has been completed.
A for loop with an identifiable loop index variable was programmed
in such a way that the loop body also modifies the index variable.
For example:
for( i = 0; i < 100; i++ )
{
a[i++] = 0;
}
In general it is better to restrict modifications to for loop index
variables to the for clause if at all possible. If this is not possible,
you can prefix the for loop with an appropriate lint comment such as:
/*lint -e{850} i is modified in the body of the for loop */
The message is parameterized with a type category which is one of:
integral some form of integer
float some form of floating point number
string some form of char * including wide char
pointer some form of pointer other than string
enumeration an enumeration of some kind
unclassified none of the above
This will allow you to be more selective in the delivery of messages because
you may suppress or enable messages according to these classifications.
For example:
-e850
+estring(850,integral)
+estring(850,float)
will enable Info 850 for integrals or for floats but not for other forms
of loop variables.
If you have comments or questions about this bug, please post them to our Discussion Forum |
Previous Bug - Bug #693 - May 2009