Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


I've tried to tackle this issue at https://github.com/alexchamberlain/byte-order.


You 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/b804361...


Well caught!


Nice! 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.


I'll quite happily optimise it to work with other compilers... Anything bar x86 might be a problem though...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: