upvote
I value correct code for purely selfish reasons. The most likely person to try to run my code on a BE system is me.
reply
Also, endian-correct code is usually semantically clearer. For example, if you're reading network-ordered bytes into an int, an unconditional endian swap (which will produce correct results on LE systems but not BE) is less clear than invoking a "network bytes to u32" helper.
reply
u32::from_be_bytes

u32::from_le_bytes

u32::from_ne_bytes the n stands for native

reply
There are a lot of odd (by modern standards) machines out there.

You're also the most likely person to try to run your code on an 18 bit machine.

reply
It might sound outrageous but I guard against this sort of thing. When I write utility code in C++ I generally include various static asserts about basic platform assumptions.
reply
So do I. I don't find that outrageous at all. Anyone trying to do the port to something unusual would appreciate the warning.

Granted, I still work on a fair number of big endian systems even though my daily drivers (ppc64le, Apple silicon) are little.

reply
This is much-appreciated. I’m hardly a Richard Stallman, but finding little incompatibilities after-the-fact is pretty irritating.
reply
Take a look at https://www.kermitproject.org/ckupdates.html . These quotes come from the last few years:

> [fixes] specific to VMS (a.k.a. OpenVMS),

> For conformity with DECSYSTEM-20 Kermit ...

> running on a real Sun3, compiled with a non-ANSII compiler (Sun cc 1.22)

> this is fatal in HP-UX 10 with the bundled compiler

> OpenWatcom 1.9 compiler

> OS/2 builds

> making sure that all functions are declared in both ANSI format and K&R format (so C-Kermit can built on both new and old computers)

Oooooh! A clang complaint: 'Clang also complains about perfectly legal compound IF statements and/or complex IF conditions, and wants to have parens and/or brackets galore added for clarity. These statements were written by programmers who understood the rules of precedence of arithmetic and logical operators, and the code has been working correctly for decades.'

reply
There's platform and there's platform. I assume a POSIX platform, so I don't need to check for CHAR_BIT. My code won't work on some DSP with 64-bit chars, and I don't care enough to write that check.

Many of the tests I did back in the 1990s seem pointless now. Do you have checks for non-IEEE 754 math?

reply
Well, last year clang did not define __STDC_IEC_559__, so assuming IEEE-754 math with most C compilers is a bad idea.
reply