So I'm writing a program to test the endianess of a machine and print it.
I understand the difference between little and big endian, however, from what I've found online, I don't understand why these tests show the endianess of a machine.
This is what I've found online. What does *(char *)&x mean and how does it equaling one prove that a machine is Little-Endian?
int x = 1;
if (*(char *)&x == 1) {
printf("Little-Endian
");
} else {
printf("Big-Endian
");
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…