HP-UX Cadvise Diagnostics Reference Guide (5900-1865, August 2012)

Table Of Contents
Example:
void foo(bool b, char c) {
if (b == 3) { } // warning 4275 here
if (c < 200) { } // warning 4275 here
if ((unsigned char)c < 200) { } // no warning here
}
Action:
Check the value of the constant being used in the operation. In the scenarios where the comparison
is between signed and unsigned types the problem can be fixed by using a cast.
Reference:
4276 relational operator %sq always evaluates to 'false'
Cause:
The greater than or less than relational operation in the expression always evaluates to false. This
happens when comparing against the largest and smallest values in the range of given type.
Example:
void foo(unsigned char c) {
if (c > 255) {} // warning 4276 here
}
NOTE: 255 is the largest value for an unsigned char so a >
comparison will always be false.
Action:
Check the value of the constant being used in the operation.
Reference:
4277 logical AND with a constant, do you mean to use '&'?
Cause:
Using a constant in a logical AND (&&) operation is rather unusual. This usually indicates a typo
where the programmer actually meant to say bitwise AND (&). This warning is not generated for
the constant 0 since that often results from macro expansions.
Example: result = value && 0x1; // warning 4277 here
Action:
Check if you meant to use '&' instead of '&&'. For certain macro expansions this can be valid
code, suppress this warning for those macros using the +Wmacro option.
Reference:
4278 the sub expression in logical expression is a constant
Cause:
Logical operators follow short-circuit evaluation - if the first operand of a logical || or && operator
determines the result of the expression, the second operand will not be evaluated. In the given
expression the first sub expression is a constant that determines the result of the expression and
hence the rest of the expression will never be evaluated.
Example:
int main() {
int a = 10;
if( 10 || (a == 10))
return 0;
}
4276 relational operator %sq always evaluates to 'false' 61