Click on image to see enlargment
Checking that a simple string will read the same forwards as backwards should be easy, but this program reports that "rotator" is not a palindrome. What's the problem?
bug866.cpp lint Output
--- Module: bug866.cpp (C++) _ for( i = 0, n = sizeof(word-1) - 1; bug866.cpp(6) : Info 866: Unusual use of 'ptr-int' in argument to sizeof
Reference Manual Explanation
866 Unusual use of 'String' in argument to sizeof -- An expression used as an argument to sizeof() counts as "unusual" if it is not a constant, a symbol, a function call, a member access, a subscript operation (with indices of zero or one), or a dereference of the result of a symbol, scoped symbol, array subscript operation, or function call. Also, since unary '+' could legitimately be used to determine the size of a promoted expression, it does not fall under the category of "unusual". Example: char A; unsigned end = sizeof(A - 1); // 866; Programmer probably meant // 'sizeof(A) - 1' size_of_promoted_char = sizeof(+A); // '+' makes a difference here size_t s1 = sizeof( end+1 ); // 866: use +end to get promoted type size_t s2 = sizeof( +(end+1) ); // OK, we won't complain struct B *p; // B is some POD. B b1; memcpy( p, &b1, sizeof(&b1) ); // 866; intended to take sizeof(b1) size_t s3 = sizeof(A); // OK, get the size of an element. size_t s4 = sizeof(A); // 866; Not incorrect, but ... // unusual in a sizeof().
If you have comments or questions about this bug, please post them to our Discussion Forum
Previous Bug - Bug #592 - February 2010