4 ms·
> E.g. signed integer overflow did exactly what you expect in most compilers until fairly recently. How recently? Both gcc 4.1.2 (2007) and clang 3.0.0 (2011)
by steerablesafe 6y ago
> E.g. signed integer overflow did exactly what you expect in most compilers until fairly recently.
How recently? Both gcc 4.1.2 (2007) and clang 3.0.0 (2011) optimizes `x+1 > x` to true for a signed int `x` on -O1. And it probably goes way back, these are just the oldest compilers I found on godbolt.
https://c.godbolt.org/z/sdd15c https://c.godbolt.org/z/sdd15c
- lmm 6y agoAh, point taken, but that's within the bounds of what many people expect; propagating the fact that the overflow is "impossible" to rearrange earlier control flow is more surprising and more recent.
- steerablesafe 6y ago> Ah, point taken, but that's within the bounds of what many people expect; The thing is it's very hard to draw the line once you go that route. Different people expect different things from undefined behavior. The best thing is to not expect anything sane. And if you are unhappy about certain undefined behaviors in the standard then it's better to push the standard to define more behavior. Certain unnecessary undefined behaviors get resolved with newer standards, although I would expect significant pushback on defining the behavior signed integer overflow.
- lmm 6y agoI understand there's a good chance the next standard will specify that signed integer overflow results in an unspecified value, which would match the behaviour of older compilers and what (IME) most programmers tend to expect.
- steerablesafe 6y ago> I understand there's a good chance the next standard will specify that signed integer overflow results in an unspecified value Do you have a source for this?
- lmm 6y agoIt was linked from a discussion on HN but I didn't record where.