3 ms·
I would not follow Linus advice here. To stick with a given endianess for a protocol? Sure! But why to use BE if everything is LE? If you use LE at compile time
by antirez 12y ago
I would not follow Linus advice here. To stick with a given endianess for a protocol? Sure! But why to use BE if everything is LE? If you use LE at compile time you can convert the conversion calls to no operations: zero cost. The cost will be incurred only into BE systems that are every day less common. So my suggestion is to stick to a specific endianess in protocols and serialization factors but picking LE instead of BE. Macros to convert the value that will do nothing if the host is already LE are trivial to write.
- loopbit 12y agoI might be missing something here, but I'd say that you are following exactly Linus' advice :)
- njloof 12y agoOn modern architectures the byte swap is effectively free, if it is done at the time the data is read or written. Worry more about code that touches data just to swap bytes, which may have to page data in.
- toyg 12y agoThat's what Linus is saying: hey, BE is basically dead and you shouldn't use it, but if you really really want to use it, that's fine as long as you don't go for dynamic switching.