4 ms·
Fun fact: if there were no C language definition, there would be no "undefined behavior."
by btrask 6y ago
Fun fact: if there were no C language definition, there would be no "undefined behavior."
- steerablesafe 6y agoIn that case all C program behavior would be literally undefined.
- btrask 6y agoIs 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.
- steerablesafe 6y agoPython 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.
- btrask 6y agoIf you remove the standard, wouldn't everything naturally be implementation-defined? Like, say, Python.
- nwmcsween 6y agoYep 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.
- btrask 6y agoHave 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.