Endianness manipulation - is there a C library for this?

Posted by Malvineous on Stack Overflow See other posts from Stack Overflow or by Malvineous
Published on 2010-04-03T10:20:14Z Indexed on 2010/04/03 10:23 UTC
Read the original article Hit count: 292

Filed under:
|

Hi all,

With the sort of programs I write (working with raw file data) I often need functions to convert between big and little endian. Usually I write these myself (which is covered by many other posts here) but I'm not that keen on doing this for a number of reasons - the main one being lack of testing. I don't really want to spend ages testing my code in a big endian emulator, and often just omit the code for big endian machines altogether. I also would rather make use of faster functions provided by various compilers, while still keeping my programs cross-platform.

The only things I can find are socket calls like htons() but they require different #include files on each platform, and some GPL code like this, however that particular file, while comprehensive, seems to miss out on some of the high performance functions provided by some compilers.

So, does anyone know of a library (ideally just a .h file) that is well tested and provides a standard set of functions for dealing with endianness across many compilers and platforms?

© Stack Overflow or respective owner

Related posts about c

    Related posts about endianness