HP Code Advisor Diagnostics

on endianness, and a character member, which does not depend on endianness, and the value
of the union is stored using one member and accessed using the other.
Example:
union Endian { char c[4]; int v; }; // warning 4289 here
int foo() {
union Endian u = { 0x11, 0x22, 0x33, 0x44 };
int i = u.v;
return i;
}
// On a big endian machine value of i will be 0x11223344 whereas
// on a little endian machine it will be 0x44332211
Action:
For portable code change the way this union is used. Do not use unions for converting values
from one type to another.
Reference:
4290 endian porting: the initialization of char array may be endian
dependent
Cause:
A char array is being initialized using hexadecimal values. It is likely that this array will later be
accessed as an integer. Based on endianness of a machine on which code is executed the value
of this integer will differ.
Example:char a[4] = { 0x11, 0x22, 0x33, 0x44 }; // warning 4290 here
Action:
For portable code check how this array is used.
Reference:
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:
4295 abstract function type declared with empty parentheses, consider
replacing with parameter list or void.
Cause:
4290 endian porting: the initialization of char array may be endian dependent 67