kc9udx How can I know which endian I'm using?
One way is:
gcc -E -dM - < /dev/null | fgrep -i end
Another is:
#include <stdio.h>
int main(void) {
union {
unsigned char c[4];
unsigned int i;
} u;
u.i = 0x12345678;
printf("%02x %02x %02x %02x\n", u.c[0], u.c[1], u.c[2], u.c[3]);
if (u.c[0] == 0x78 && u.c[3] == 0x12)
printf("Little-endian\n");
else if (u.c[0] == 0x12 && u.c[3] == 0x78)
printf("Big-endian\n");
else
printf("PDP-11?\n");
return 0;
}
Non-portable, but, WTH...