2 ms·
What does it mean to have an "explicitly-endian" type? In the register, it's all the same thing. I have seen tons of code with #if BIG_ENDIAN ... and it's a hu
by chongli 3y ago
What does it mean to have an "explicitly-endian" type? In the register, it's all the same thing.
I have seen tons of code with #if BIG_ENDIAN ... and it's a huge nightmare. Follow the Rob Pike way [1] and regain sanity.
[1] https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html https://commandcenter.blogspot.com/2012/04/byte-order-fallac...
- corysama 3y agoNot just sane, but fast too. Compilers have long been able to recognize this algo and will optimize all those bit ops to a single BSWAP assembly instruction as necessary.
- cperciva 3y agoWhat does it mean to have an "explicitly-endian" type? In the register, it's all the same thing. An integer type with an explicit representation in memory. In this case, "arithmetic works like a uint32_t, but when you're storing it to memory, do it in big-endian format". Follow the Rob Pike way [1] and regain sanity. This is the Rob Pike way, except it would involve the compiler writing the code for converting between uint32_t and uint8_t[4].