Hacker News new | past | comments | ask | show | jobs | submit login

"undefined" means "defined elsewhere".





LOL. No.

Some languages/libraries even make an explicit distinction between Undefined and Implementation-Defined, where only the latter is documented on a vendor-by-vendor basis. Undefined Behavior will typically vary across vendors and even within versions or whatnot within the same vendor.

The very engineers who implemented the code may be unaware of what may happen when different types of UB are triggered, because it is likely not even tested for.


So it's defined in the compiler's source code. God doesn't roll a die every time you dereference null. Demons flying out of your nose would conform to the C++ standard, but I assure you that it would violate other things, such as the warranty on your computer that says it does not contain nasal demons, and your CPU's ISA, which does not contain a "vmovdq nose, demons" instruction.

No. The compiler isn't the only component of the system that will determine what happens when you trigger UB, either. There is UB all the way down to hardware specifications.

I used to be one of the folks who defined the behavior of both languages and hardware at various companies. UB does not mean "documented elsewhere". Please stop spreading misinformation.


> No. The compiler isn't the only component of the system that will determine what happens when you trigger UB, either. There is UB all the way down to hardware specifications.

I don't think you know what undefined behavior is. That's a concept relevant to language specifications alone. It does not trickle up or down what language specifications cover. It just means that the authors of the specification intentionally left the behavior expected from a specific scenario as undefined.

For those who write software targeting language specifications this means they are introducing a bug because they are presuming their software will show a behavior which is not required by the standard. For those targeting specific combinations of compiler and hardware, they need to do their homework to determine if the behavior is guaranteed.


Hardware also has UB, but what happens is still dictated by the circuitry. The relevant circuitry is both complicated enough and not useful enough for the CPU designer to specify it.

Often they use the word "unpredictable" instead. The behavior is perfectly predictable by an omniscient silicon demon, but you may not be able to predict it.

The effect that speculative execution has on cache state turned out to be unpredictable, so we have all the different Spectre vulnerabilities.

Hardware unpredictability doesn't overlap much with language UB, anyway. It's unlikely that something not defined by the language is also not defined by th hardware. It's much more likely that the compiler's source code fully defines the behaviour.


"I used to be one of the folks who defined the behavior of both languages and hardware at various companies"

But not at all companies, orgs or even in Heaven and certainly (?) not at ISO/OSI/LOL. It appears that someone wants to redefine the word "undefined" - are they sure that is wise?


> LOL. No.

It actually does. You should spend a minute to learn the definition before commenting on the topic.

Take for example C++. If you bother to browse through the standard you'll eventually stumble upon 3.64 where it states in no uncertain terms that the definition of undefined behavior is "behavior for which this document imposes no requirements". The specification even goes to the extent of subclassifying undefined behavior in permissible and how it covers the program running in a documented manner.

To drive the point home, the concept of undefined behavior is something specific to language specifications,not language implementetions. It was introduced to allow specific existing implementations to remain compliant even though they relied on very specific features, like particular hardware implementetions, that once used may or may not comply with what the standard specified as required behavior and went beyond implementetion-defined behavior.

I see clueless people parroting "undefined behavior" as some kind of gotcha, specially when they try to upsell some other programming language. If your arguments come from a place of lazy ignorance, you can't expect to be taken seriously.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: