Re:Undefined behavior in C is a reading error
by rndgermandude on Friday May 21, 2021 @02:54AM
(#27231225)
Yes, thankfully at least with NULL they didn't fall into the legacy trap and messed up the standard with non-zero NULL that some machines before have been kind of using.
>Defining signed integer overflow to wrap, for example, is probably a bad idea
I wouldn't call it great behavior, but it's at least what most people expect will happen, and most people will be able to understand what's going on, and it's fast on most systems that matter. However, it's still undefined behavior. Just codifying overflows to be wrapping, would therefore be an improvement in my opinion, at least over what we have today.
Re:Undefined behavior in C is a reading error
by gpderetta on Friday May 21, 2021 @04:55AM
(#27231838)
I would say that most people expect it not to happen. If they really had to mandate a behavior, it should be to trap.
But, to address the content of your comment: defined behavior at runtime is not necessarily good behavior at runtime. Defining signed integer overflow to wrap, for example, is probably a bad idea, because this is rarely the intent of the code. Having all such operations trap might be a good idea, but now you're going to get the same "stop breaking my working programs" people angry at you.