3 ms·
It kind of did if I recall correctly, but in the most infuriating way possible: signed overflow is still undefined!
by loup-vaillant 3y ago
It kind of did if I recall correctly, but in the most infuriating way possible: signed overflow is still undefined!
- renox 3y agoBlame the CPU makers. Fun fact: in Zig, unsigned overflow are undefined too.
- kps 3y agoZig does have modular `+%` and saturating `+|` operators, as well as `@addWithOverflow()`, though. You get to choose what happens on overflow; if you don't, the compiler gets to.
- loup-vaillant 3y agoI’ll blame CPU makers when you can name one CPU in current use that isn’t bog standard 2’s complement that wraps around by default. About Zig, you probably meant implementation defined, or at the very worst unspecified. In C standard parlance those aren’t undefined at all. They can’t encrypt your hard drive just because you relied on them. Undefined behaviour however, can. And does, when UB happens to enable an arbitrary code execution vulnerability.
- nullc 3y agohaving overflow of a common loop type be undefined is extremely useful for optimization, since many kind of unrolling and vectorization approaches only work if you can assume the loop counter cannot wrap.