I did some googling and couldn\'t find any good article on this question. What should I watch out for when implementing an app that I want to be endian-agnostic?
If you need to reinterpret between a 2,4 or 8 byte integer type and a byte-indexed array (or visa versa), than you need to know the endianness.
This comes up frequently in cryptographic algorithm implementation, serialization applications (like network protocol, filesystem or database backends), and of course operating system kernels and drivers.
It is usually detected by a macro like ENDIAN... something.
For example:
uint32 x = ...;
uint8* p = (uint8*) &x;
p is pointing to the high byte on BE machines, and the low byte on LE machine.
Using the macros you can write:
uint32 x = ...;
#ifdef LITTLE_ENDIAN
uint8* p = (uint8*) &x + 3;
#else // BIG_ENDIAN
uint8* p = (uint8*) &x;
#endif
to always get the high byte for example.
There are ways to define the macro here: C Macro definition to determine big endian or little endian machine? if your toolchain doesnt provide them.