5 ms·
I think there are valid reasons for a language spec to have Undefined behavior. But many UB in C would be much better if the where defined as platform specific.
by quelsolaar 6y ago
I think there are valid reasons for a language spec to have Undefined behavior. But many UB in C would be much better if the where defined as platform specific. Like integer overflow, its very well defined on x86, ARM and every other CPU architecture in use, but not only does compilers act as if its unknowable, even when they clearly know it because they are implementing a known instruction set, they even make it hard to detect overflows since they optimize away tests since they cant happen.
- klodolph 6y agoI’d say that Annex L does get you closest to that goal, in that “bounded undefined behavior” can result in indeterminate values. > …not only does compilers act as if its unknowable… I disagree with this interpretation. The compiler is acting not as if it’s unknowable, but as if it doesn’t happen.
- MauranKilom 6y agoSurely you understand why compilers do this, right? This isn't compilers and standard writers being mean because they hate you. This is a language that you choose for speed being optimal for speed. In particular, signed integer overflow being UB was and still is a necessary evil so that compilers don't have to add ugly loop preambles to every loop you write.