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

"Undefined behavior" is a quirk of the C++ ISO standard legalese, not some property of computing or of the C++ language.

Briefly, the C++ standard defined three classes of stuff that isn't covered by the standard:

Implementation-defined behavior - "behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation documents".

Unspecified behavior - "behavior, for a well-formed program construct and correct data, that depends on the implementation".

Undefined behavior - "behavior for which this document imposes no requirements".

So 'undefined behavior' is stuff that isn't mandated by the standard and also may or may not be an error.

Some UB stuff is bugs (like accessing arrays out of bounds), some isn't bugs but just processor/OS dependent stuff that is out of scope of the C++ standard. (Like what happens when integers overflow.)

In short, the existence of UB is a good thing; having a standard that clearly states what is part of it and what isn't is vastly better than a standard that mandates too much or is too vague.

(And it goes without saying that having no standard at all, like is usual for other programming languages in 2019, is worse in every way.)



I'd rather have a language with no standard and no UB than one with a standard and UB.


since the language has no standard, from the point of view of ISO, using the whole language itself is UB :-)


If ISO want to come round and do some programming for me, i will be happy to discuss it with them!


Then you can still use C++. Just replace all the UB in the standard with whatever your particular compiler & hardware platform do.




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

Search: