Praveen's Blog

An Eternal Quest for Incremental Improvement

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.

 // Do some big endian stuff
 // Do some little endian stuff
 // Do some PDP endian stuff
 // Do something else

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 __BYTE_ORDER and __BIG_ENDIAN evaluated to null and the condition #if null == null evaluates to true always. Funny!!!