Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That’s not at all the same thing.


What is the difference between "writing past the end of an array is UB" and "dereferencing a null pointer is UB" and "passing null as the destination argument to memcpy is UB"? The two programs I listed above are only observationally equivalent if writing past the end of valid allocations is UB.

A core problem with this discussion in almost all circumstances is that people have a vibe for which of these things it feels okay for a compiler to make logical deductions from and which it feels not okay but if you actually sit down and try to formalize this in a way that would be meaningful to compiler vendors, you can't.


You are still completely missing the point.

This example is not "I know that UB doesn't happen, therefore ...", which is what the memcpy() case is.

It is "I don't care that UB might happen, I am going to act as if it didn't. If the UB then makes the program behave differently than without the UB, that's not my problem".

Which, incidentally, is one of the suggested/permitted responses to UB in the standards text (that was made non-binding).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: