quote:Original post by PyroMeistar
My engine (Avangion) is platform-independant (Works on Windows and Unix based systems). The matter concerning little and big endian is annoying but can be resolved quite easily. First, find out what system your engine is compiled on by using #ifdef. Windows works with little endian while Linux works with big endian. Then, simply #define some macros that automatically convert the data if it is necessary. Here is some pseudo-code:
#ifdef LITTLE_ENDIAN
#define SWAP16LE(x) (x)
#define SWAP32LE(x) (x)
#define SWAP16BE(x) Swap16(x)
#define SWAP32BE(x) Swap32(x)
#endif
#ifdef BIG_ENDIAN
#define SWAP16LE(x) Swap16(x)
#define SWAP32LE(x) Swap32(x)
#define SWAP16BE(x) (x)
#define SWAP32BE(x) (x)
#endif
The Swap16 & Swap32 functions simply switch the high order byte(s) with the low order one(s) using bitwise ops.
Hope that helps!
Linux is little endian on little endian architectures and big endian on big endian ones. It is little endian on x86 for instance, and big endian on PPC.
There is also much more to portability than endianness (binary representation of floating point values, threads, networking and other system calls, file I/O, etc). Now if your project is small, you can probably just forget this, as long as you avoid storing 3D data in binary files and don''t use sizeof(structure) to read from a file (because of padding).
Hope this helps.