▲ | IshKebab 4 days ago | |
This asserts that UB was deliberately created for optimisation purposes; not to handle implementation differences. It doesn't provide any evidence though and that seems unlikely to me. The spec even says: > behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements No motivation is given that I could find, so the actual difference between undefined and implementation defined behaviour seems to be based on whether the behaviour needs to be documented. | ||
▲ | flohofwoe 4 days ago | parent [-] | |
I'd say the original intent of UB was not the sort of "optimizer exploits" we see today, but to allow wiggle room for supporting vastly different CPUs without having to compromise runtime performance or increasing compiler complexity to balance performance versus correctness. Basically an escape hatch for compilers. The difference to IB also has always been quite fuzzy. Also the C spec has always been a pragmatic afterthought, created and maintained to establish at least a minimal common feature set expected of C compilers. The really interesting stuff still only exists outside the spec in vendor language extensions. |