My library needs to read-in big-endian integers (4-bytes) and covert them to the endian order of the host for processing. While on *nix ntohl
has worked a treat under Windows use of ntohl
requires the use of Ws2_32.dll
(Winsock).
Such a dependency is one which I would rather eliminate. The simplest way to do this appears to be to write my own endian-swapping function (a trivial exercise, considering performance is not a real concern). However, this requires a way to determine the endianness of the system my library is being compiled on (so I can #ifdef
out the swapping function on big endian systems).
As there appears to be no standard preprocessor definition for endianess it appears as if it is necessary to determine it using my build system (cmake). What is the best means of doing this? (I am weary of 'compile a test file and see' type solutions as they would appear to inhibit cross-compiling.)