Re:Undefined behavior is often a thing for C programmers (2011)
by dooglius on Thursday September 03, 2020 @01:09PM
(#24366170)
You could come up with hardware that does this for any aspect of the spec though. For instance, I could make an ISA whose ADD instruction was normal except that 2+2=5. Adding a check around each add instruction would certainly be very expensive. Does the existence of this mean that we should redefine addition (on _all_ hardware) to avoid the penalty? Would compilers for other architectures be justified in eliding `if(x+y==z) foo();` if it can prove that `x` and `y` are `2`?
[ Parent
| on HN ]
Re:Undefined behavior is often a thing for C programmers (2011)
by chrisseaton on Thursday September 03, 2020 @04:12PM
(#24368336)
> For instance, I could make an ISA whose ADD instruction was normal except that 2+2=5.
Yeah, but good luck selling that... for the reasons you've identified it'd be a nightmare to run C on it.