Something like this:
unsigned short num; unsigned char * array; num = 0xFF00; array = (char *) num; if(array[0] = 0x00) { printf("littileEndian"); } else { printf("bigEndian"); }
typedef enum { LITTLE_ENDIAN, BIG_ENDIAN } endian; endian check_endian(void) { int x=1; if(*(char*)&x==1) return LITTLE_ENDIAN; else return BIG_ENDIAN; }
Doesnt the compiler know when it is compiling your program since it is required to have detailed knowledge about the target platform? Seems like the kind of thing you could check with a macro.
Looks like GCC defines __BYTE_ORDER__ and some associated macros: http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
How we can add two 64 bit number on 32 bit machine using c/c++ program ?