HP Code Advisor Diagnostics Reference Guide (5900-1865, July 2011)
int main()
{
int *p;
short q = 0x0123;
p = (int *)&q;
printf("%d\n", *p);
}
On a big-endian system, the output is: 19070976. Whereas, on a little-endian system, the output
is: 291
Action:
Pointer type casting to different data size is unusual, and might be done by mistake - check if this
is what you intended.
Reference:
2.152 4365 endian porting: the definition of the union may be endian
dependent
Cause:
The values accessed using the members of a union may differ based on endianness of a machine
in which the code is executed. This occurs when the union has members of different sizes, and
when the value stored using one member is accessed using another of a different size.
Example:
#include <stdio.h>
union endian { short s; int i; char c;};
int main() {
union endian u;
u.i = 0x01234567;
printf("%hx\n", u.s);
return 0;
}
cadvise displays the following warning when the option +Ww4365 is passed to it.
"/path/1.c", line 2: warning #4365-D: endian porting: the definition
of the union may be endian dependent
The field s is incompatible with field(s) i, c
The field i is incompatible with field(s) s, c
The field c is incompatible with field(s) s, i
union endian {
Action:
Avoid using unions to convert from one type to another of different size.
Reference:
2.153 4370 Control flows into the switch case from the previous case
value
Cause:
Occurs when there is a fall-through case statement within a switch.
Example:
#include <stdio.h>
int foo(int a) {
switch (a) {
case 1: printf("One\n");
2.152 4365 endian porting: the definition of the union may be endian dependent 69