Re:Big-Endian Testing with QEMU
by j16sdiz on Friday April 03, 2026 @11:30AM
(#47627871)
If you comes to low level network protocol (e.g. writing a TCP stack), the "network byte order" is always big-endian.
[ Parent
| on HN ]
Prometheus index format is also a big-endian binary file - haven’t found any reference to why it was chosen.
Re:Big-Endian Testing with QEMU
by edflsafoiewq on Friday April 03, 2026 @12:59PM
(#47629145)
That's a serialization format.
It goes without saying that all binary network protocols should document their byte order, and that if you're implementing a protocol documented as big endian you should use ntohl and friends to ensure correctness.
However if designing a new network protocol, choosing big endian is insanity. Use little endian, skip the macros, and just add
#ifndef LITTLE_ENDIAN
#error
Or the like to a header somewhere.
Re:Big-Endian Testing with QEMU
by AnthonyMouse on Friday April 03, 2026 @02:32PM
(#47630268)
What does it actually cost you to define a macro which is a no-op on little endian architectures and then use it at the point of serialization/deserialization?
A lot because to the compiler a no-op macro is the same as not having the macro in the same place so it won’t catch cases where you should use the macro but didn’t. Then you just give yourself a false sense of security unless you actually test on big endian.
Re:Big-Endian Testing with QEMU
by AnthonyMouse on Friday April 03, 2026 @03:36PM
(#47631139)
The article demonstrates how you can run your existing test suite on big endian with a few simple commands. Or you can just wait until someone actually wants to use it there, they run your program or test suite on their actual big endian machine and then you get a one-line pull request for the place you forgot to use the macro.
Adding other architectures to your build system also tends to reveal nasty bugs in general, e.g. you were unknowingly triggering UB on all architectures but on the one you commonly use it causes silent data corruption whereas one with a different memory layout results in a much more conspicuous segfault.
And honestly at this point it's mostly a historical artifact, if we write that kind of stuff then sure we need to care but to produce modern stuff is a honestly massive waste of time at this point.
FWIW I doing hobby-stuff for Amiga's (68k big-endian) but that's just that, hobby stuff.