|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page bug682.cpp
The programmer expected that summing the elements of the array would produce the value 10. Instead he got something much smaller. What did he do wrong? bug682.cpp lint Output
--- Module: bug682.cpp
_
int limit = sizeof(a) / sizeof(int);
bug682.cpp(7) : Warning 682: sizeof applied to a parameter 'a' whose type is a
sized array
_
}
bug682.cpp(12) : Info 818: Pointer parameter 'a' (line 5) could be declared as
pointing to const
Reference Manual Explanation
682 sizeof applied to a parameter 'Symbol' whose type is a
sized array -- If a parameter is typed as an array it is
silently promoted to pointer. Taking the size of such an
array will actually yield the size of a pointer.
Consider, for example:
unsigned f( char a[100] ) { return sizeof(a); }
Here it looks as though function f() will return the value
100 but it will actually return the size of a pointer,
which is usually 4.
If you have comments or questions about this bug, please post them to our Discussion Forum |
Previous Bug - Bug #681 - May 2002