4 ms·
The thing is, reading past the bounds of an array can be harmless at the machine level and useful for optimization. So it being UB means you've got a compiler
by _yosefk 11y ago
The thing is, reading past the bounds of an array can be harmless at the machine level and useful for optimization.
So it being UB means you've got a compiler which can optimize better but the cost is that you tied the programmer's hands, so the programmer's optimization opportunities are in fact reduced. And you didn't even tie them, the annoying thing is, rather you laid traps that they can fall into because of failing to notice them.
(I'm not saying C made the wrong tradeoff with declaring this or that UB, just that the tradeoff exists.)