We want to write endian-independent code in C using some preprocessor directive. Can we define a preprocessor directive which will help us to check endianness of the machine during compile time? We want something like below sample code. Any help would be appreciated.
#if(some conditions)
#define LITTLE_ENDIAN 1
#else
#define LITTLE_ENDIAN 0
#endif
I know there are several solutions but those are not fulfilling my requirement. I don't want to compile little endian specific code in a big endian machine and the vice versa. For example
#if LITTLE_ENDIAN
line1..
line2..
line3..
#else
line4..
line5..
line6..
#endif
In big endian machine I don't want to compile lines 1,2 and 3. Those three lines should be disabled.