3 ms·
> It is virtually inconceivable that a mainstream compiler stack would do anything other than what you'd expect with example four. I disagree. I can easily c
by FartyMcFarter 7y ago
> It is virtually inconceivable that a mainstream compiler stack would do anything other than what you'd expect with example four.
I disagree.
I can easily conceive of a (compiler, architecture, compiler options) tuple that simply crashes with an error at compile time or runtime with that code. Namely, some compiler for a 16-bit architecture with "sanitization" options enabled and optimizations disabled.
Integer overflow is one of the easiest "undefined behavior" cases to identify with mechanical checks. Much easier than bounds checking for example, where a general solution is quite tricky.
- microcolonel 7y agoSure, but portable C programs are not written for systems with 16-bit machine words practically ever anymore. Nobody's expecting to run libopus 1.3.1 unmodified on an 8051 (even if it might well do, it probably uses stdint.h anyway!). Furthermore, I've used toolchains for machines with 16-bit machine words, which made int 32 bits; surely this isn't uncommon.