3 ms·
The smallest questions always cause the most heated debate. It doesn't really matter much how the possible byte order swap is done: what matters that these ifd
by yason 15y ago
The smallest questions always cause the most heated debate.
It doesn't really matter much how the possible byte order swap is done: what matters that these ifdefs aren't littered around the code and byte-order swapping is limited to the lowest level where data is actually read from an external source.
I would personally go with his byte array reads as it's less confusing but I would still wrap the functionality inside inlined functions like these:
uint32_t inline read_be32 (void*);
uint32_t inline read_le32 (void*);
And then use these whenever reading 32-bit integers from big-endian or little-endian data source.
- alexchamberlain 15y agoI've tried to tackle this issue at https://github.com/alexchamberlain/byte-order https://github.com/alexchamberlain/byte-order.
- dchest 15y agoYou did this to prove Pike's argument, didn't you? Whenever I see code that asks what the native byte order is, the odds are about a hundred to one the code is either wrong or misguided. https://github.com/alexchamberlain/byte-order/commit/b804361636f9233a6c9b0b38b04ceef98f3e8faa#L0L64 https://github.com/alexchamberlain/byte-order/commit/b804361...
- alexchamberlain 15y agoWell caught!
- haberman 15y agoNice! I think I'll use this. I was going to suggest also including calls to platform-specific byte swapping functions for compilers other than GCC, but maybe it's better to wait until it's actually demonstrated to be a benefit.
- alexchamberlain 15y agoI'll quite happily optimise it to work with other compilers... Anything bar x86 might be a problem though...