4 ms·
>Byte swapping is important when transferring data between system that use different order for the sequence of bytes stores in memory. That seems like a glarin
by simias 4y ago
>Byte swapping is important when transferring data between system that use different order for the sequence of bytes stores in memory.
That seems like a glaring footgun to me, to the point where I think I must be missing something.
What I want when dealing with endianess are "from_little_endian/to_little_endian", "from_big_endian/to_big_endian" function pairs that expand to either nop or a byte swap depending on the host architecture.
Exposing the byte swapping directly without this layer on top is asking for trouble because every user will have to make sure that they correctly detect the local endianess before attempting a swap. That's the potentially tricky part, not swapping the bytes.
- gpderetta 4y agoThe std::endian enum makes it very easy to find the native endianness.
- a1369209993 4y agoThat's irrelevant, because there's nothing useful you can do with the native endianness (other than implement (load/store)_(big/little)_N for various combinations of options).
- gpderetta 4y agoyou can use it to implement native_to_be or native_to_le, it seems pretty useful to me. In fact, what can't it do?