3 ms·
If you don't go by the spec, what do you go by? To quote the standard, "a documented manner characteristic of the environment." If the machine is two's comple
by userbinator 11y ago
If you don't go by the spec, what do you go by?
To quote the standard, "a documented manner characteristic of the environment."
If the machine is two's complement (which is the vast majority of them), then you'd expect that behaviour. If it's sign-magnitude or one's complement or saturating, then the behaviour would be different but still consistent.
Even if you don't care about the optimization, is it not equally surprising that such a statement could ever be `false`?
Overflows wrapping around is not surprising, it's what decades of computing hardware (or centuries if you include mechanical calculators like https://en.wikipedia.org/wiki/Pascal%27s_Calculator https://en.wikipedia.org/wiki/Pascal%27s_Calculator ) have always done.
- stouset 11y ago> If the machine is two's complement (which is the vast majority of them), then you'd expect that behaviour. If it's sign-magnitude or one's complement or saturating, then the behaviour would be different but still consistent. How is this different in practice from undefined behavior, other than the compiler can't take advantage of it for optimizations?