logoalt Hacker News

fc417fc802yesterday at 4:52 PM3 repliesview on HN

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.


Replies

classichasclassyesterday at 6:13 PM

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.

peytonyesterday at 6:09 PM

This is much-appreciated. I’m hardly a Richard Stallman, but finding little incompatibilities after-the-fact is pretty irritating.

show 1 reply
eesmithyesterday at 6:15 PM

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?