HP Code Advisor Diagnostics Reference Guide (5900-1865, July 2011)
2.136 4292 endian porting: the dereference of cast pointer may be endian
dependent
Cause:
A pointer of integral type is being cast to a pointer of char or smaller integer type. Based on
endianness of a machine on which code is executed the value accessed using will differ.
Example:
unsigned int value = 0x03020100;
unsigned int *ptr =
unsigned char charVal;
void foo() {
charVal = *(unsigned char *)ptr; // warning 4292 here
charVal = *(unsigned char *)(void*)ptr; // no warning
}
Action:
For portable code change the way these values are accessed. If the order in which the values are
accessed is not important then first cast the pointer to void* type and then cast to the lesser integer
type.
Reference:
2.137 4295 abstract function type declared with empty parentheses,
consider replacing with parameter list or void.
Cause:
The declaration of function has an empty parameter list. If the function has parameters, they should
be declared here; if it has no parameters,void should be specified in the parameter list.
Example: void foo(long (*compar) ()) ;
Action:
The recommended way to declare a function that takes no parameters is to use void in the parameter
list.
Reference:
2.138 4298 64 bit migration: addition result could be truncated before
cast to bigger sized type
Cause:
The size of the result of an operation is determined based on the size of the operands and not
based on size of variable in which the resultant value is stored. If the result exceeds the size of the
operands, in this case 32 bits, it will be truncated even before the assignment takes place.
Example:
void foo(int data) {
long data1 = data + 16; // warning 4298 here
long data2 = ((long)data) + 16; // no warning
}
Action:
If you expect the value of the result to exceed the size of the type of operands then cast the operands
to the bigger type before addition else use same type for operands and result.
Reference:
64 Diagnostics Details