4 ms·
> This also means they could define integer overflow as 2's complement rollover, which is almost universal but is still considered undefined behavior. No, they
by zajio1am 4y ago
> This also means they could define integer overflow as 2's complement rollover, which is almost universal but is still considered undefined behavior.
No, they should not. Integer overflow is in most cases logic error, like division by zero or NULL pointer dereference, so it should stay undefined.
- pantry-man 4y agoIt can still be well defined behaviour and still an error
- marssaxman 4y agoThat's only true for the relatively recent and generally unhelpful "nasal demons" interpretation of undefined behavior; under the older concept, which is more like "do whatever the sensible thing would be on the target platform", rollover is probably just what you want.
- zajio1am 4y agoDistinction between undefined, unspecified, and implementation-defined is already in ISO C99 specification and is rather specific: "NOTE: Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (...), to terminating a translation or execution (...)." > which is more like "do whatever the sensible thing would be on the target platform" That is a meaning of 'implementation-defined' in C parlance.
- marssaxman 4y agoI am familiar with the verbiage in the specification. My contention is that the currently popular tendency for C compilers to generate code which behaves in ways that are absurd and unpredictable, on the grounds that you shouldn't have been doing that anyway, is an unhelpful indulgence on the part of the compiler engineers.