int x = 1;or a union:
if(*(char *)&x == 1)
printf("little-endian\n");
else printf("big-endian\n");
union {
int i;
char c[sizeof(int)];
} x;
x.i = 1;
if(x.c[0] == 1)
printf("little-endian\n");
else
printf("big-endian\n");
int x = 1;or a union:
if(*(char *)&x == 1)
printf("little-endian\n");
else printf("big-endian\n");
union {
int i;
char c[sizeof(int)];
} x;
x.i = 1;
if(x.c[0] == 1)
printf("little-endian\n");
else
printf("big-endian\n");
No comments:
Post a Comment