Endian check confusion
I was debugging a malfunctioning code in my project. The part of the code that I debugged involved some endian based computations. I just guessed that there might be some endian based issues in the code. But when I looked into the details of the code, they have handled the endianness properly as follows.
#if __BYTE_ORDER == __BIG_ENDIAN // Do some big endian stuff #elif __BYTE_ORDER == __LITTLE_ENDIAN // Do some little endian stuff #elif __BYTE_ORDER == __PDP_ENDIAN // Do some PDP endian stuff #else // Do something else #endif
But when I did more investigation, I found that the big endian part of code is generated inspite of the fact that I am running it on AMD64. Can you guess the reason for this?
I too was puzzled initially. But the reason was so silly. The source
file was not including
endian.h header file! Because of this both
__BIG_ENDIAN evaluated to
null and the
#if null == null evaluates to true always. Funny!!!