logoalt Hacker News

ueckertoday at 3:26 PM2 repliesview on HN

This is not quite correct in C. ISO C at least requires that observable behavior until this point is preserved.


Replies

tialaramextoday at 3:55 PM

This is important. Undefined Behaviour is a behaviour, and so if we can ensure the behaviour doesn't happen, our problem is averted. For example if there's UB when a zero size file is loaded by our software, we can instruct operators to check the file has a non-zero size and we're preventing whatever horrible UB would arise.

We can even rope off whole parts of the software. If the Postscript printing code has UB, simply instruction operators only to use the HP inkjet printers for which we know Postscript is not used can prevent this UB from happening.

titzertoday at 3:43 PM

I don't think this is true. You're going to have to point to the exact place in the spec that says this, because optimizations in the presence of UB in most compilers make absolutely no assumptions.

show 1 reply