2 ms·
> C and C++ programmers need to be taught that they must not write that. Things have stabilized quite a while ago. 99% of people who write C or C++ in 2024 wil
by Const-me 3y ago
> C and C++ programmers need to be taught that they must not write that.
Things have stabilized quite a while ago. 99% of people who write C or C++ in 2024 will never use any computers where sizeof(int) != 4, or big endian processors, or systems where floats don’t conform to IEEE-754 standard.
Why shouldn’t they write code which requires these particular details from their compiler and the target processor?
- SAI_Peregrinus 3y agoI'd say there's no issue with writing such code, so long as it's protected by a compile-time assertion. That said, if you use a variable-width integer type (`char`, `short`, `int`, `long`, `long long`) instead of a fixed-width type (`int32_t` & such) for anything other than passing parameters to existing libraries (including the standard library) I'd say you're Doing It Wrong. If you actually intend to have a variable-width, use one of the `_least` or `_fast` types to make it clear that you didn't just screw up.
- NikkiA 3y agoOne thing I think C++ (or at least, most C++ users) gets right is suggesting that you should use 'auto' if you don't really care that much about bit width, and the specified sizes otherwise. Thankfully C23 takes this approach, although it'll probably take forever until it's as adopted as widespread as C99 is now, and that's still not widespread enough.