|
|
|
|
|
by renox
620 days ago
|
|
> Zig doesn't provide any rationale for why it picked UB rather than wrapping There's no need to provide a rationale because it's obvious, from a performance POV: 1) (a) UB on overflow > (b)wrapping on overflow 2) (b)wrapping on overflow > (c)trap on overflow. So when you create a language you have to pick a default behaviour, Zig allow both (a) xor (c) with ReleaseFast and ReleaseSafe.. (1) is because this allows the compiler to do "better" optimisations, which unfortunately can create lots of pain for you if your code has a bug. (2) is because these f.. CPU designers don't provide an 'add_trap_on_overflow' instruction so at the very least the overflow check instruction degrades the instruction cache utilisation. |
|
Alas no, you've written a greater than sign but you'll find in reality it's often only the same. But you've significantly weakened the language, so you just made the language worse and you need to identify what you got for this price.
On the one hand, since you didn't promise wrapping in some cases you'll astonish your programmers when you don't provide it but that's what they expected, on the other since can't always get better performance you'll sometimes disappoint them by not going any faster despite not promising wrapping.
This might all be worth it if in the usual case you were much faster, but, in practice that's not what we see.