Remix.run Logo
7jjjjjjj 2 hours ago

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.
AnthonyMouse an hour ago | parent [-]

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?

kccqzy 20 minutes ago | parent [-]

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.