I missed a problem when I doing my homework.
Computer memory in the storage of data where there are big-endian storage and small-endian storage two methods, in order to detect a machine storage method, a student wrote the following procedure:
union NUM {
int a;
char b;
} num;
int main(){
num.b = 0xff;
if (num.a! = 0xff)
printf ("bigend");
else
printf ("smallend");
return 0;
}
But he found the program running on the x86 machine, print out is actually 'bigend', which is clearly wrong. Do you know where the problem is? How should this program be modified?
I have asked my teacher, the topic is correct. I have found some information in some websites, but it makes me more confused. Why this question is not incorrect? And where the problem actually is?