I’m curious if this function will determine endianness.
The test is a bitmask that equals 1 if the integer someInt is stored in little endian.
in the bitmask, would 0x1000 be converted to match the endian style of the machine or would it be “constant”?
#include <stdio.h>
int isBigEndian(){
int someInt =0x0001;
if(someInt & 0x0100 == 1)
return 1;
else
return 0;
}
int main(){
int returnVal = isBigEndian();
printf("return val is %d", returnVal);
}
That function will always return zero since your constants are stored in native endianness of the system as well. A much better bet is to just use an system API that answers your question. If you had to be portable, you can probably compare
val == ntohl(val)to decide endianness.