by codeflo · 2y ago · 0 comments
Turns out the author does mean according to the standard, but thinks that “I don’t know” is a synonym for both undefined and unspecified behavior. It seems weird to use imprecise terminology in a post that’s all about lecturing about standards compliance.
So it's easy to say: I don't know.
This was a semantic quiz, not a technical one.
Obligatory xkcd: https://xkcd.com/169/
In either case, is "I don't know" wrong? Given the information in this quiz, I don't think it is.
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?
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.
But taking this test, would you really check "I don't know" if you do know it is UB, when there is no option "platform specific" or "UB"?