News for hackers. Stuff that matters.
Re:Undefined behavior is often a thing for C programmers (2011) by steerablesafe on Thursday September 03, 2020 @10:41AM (#24364516)
In that case all C program behavior would be literally undefined.
Re:Undefined behavior is often a thing for C programmers (2011) by btrask on Thursday September 03, 2020 @01:39PM (#24366498)
Is that what you think of Python?

How can this be: C has a standard, when many other languages do not. Thus C is "more defined" than other languages. Yet somehow it ends up being less defined.

If C had no standard, it would be defined by its implementation, just like many other languages. But because it has a standard, it has undefined behavior.

The real trick is that without a standard, implementations have to be bug-compatible. They're too defined! The purpose of a standard is to define them less.

Re:Undefined behavior is often a thing for C programmers (2011) by steerablesafe on Thursday September 03, 2020 @01:56PM (#24366688)
Python many times had the problem of being defined as CPython. Modules that target multiple Python implementations often have to work around differences between them, without a standard they have to look into implementation details of their targets. Not having a standard is definitely a pain.

But for most intents and purposes Python is defined by its documentation, and it's fine.

Having said that UB in C and C++ means behavior that the standard doesn't define. If you remove the standard then UB either loses meaning or it makes all programs undefined. It definitely doesn't make all programs defined.

Re:Undefined behavior is often a thing for C programmers (2011) by btrask on Thursday September 03, 2020 @03:01PM (#24367491)
If you remove the standard, wouldn't everything naturally be implementation-defined? Like, say, Python.
Re:Undefined behavior is often a thing for C programmers (2011) by nwmcsween on Thursday September 03, 2020 @06:50PM (#24369741)
Yep and you would end up with what was occuring before there a standard was created (POSIX, etc) which is generally a giant dumpster fire of implementation defined hell.
Re:Undefined behavior is often a thing for C programmers (2011) by btrask on Thursday September 03, 2020 @10:18PM (#24371118)
Have you thought about why having a standard causes all these problems with undefined behavior? The point of a standard is to be less specific than a reference implementation. That's why it's written in English, not code. That means definitions are fuzzy, which is why every kind of English-language law, rule, or spec is vulnerable to malicious compliance.

If C had a judge, like the legal system, he could deny attempts to use fuzziness in the standard (intended to prevent specifying bugs) to introduce bugs. Unfortunately, C doesn't have a judge with common sense, it has people who think the standard is code and anything that is undefined really is a license to do whatever you want.

I guess this problem was inevitable as soon as the words "nasal demons" were put to keyboard. Now the only thing that can save us is a reference implementation.