3 ms·
You don't actually have to make the undefined behaviour go away completely, which is difficult. An easier approach would be to put a bound on what is permissib
by mpweiher 8y ago
You don't actually have to make the undefined behaviour go away completely, which is difficult.
An easier approach would be to put a bound on what is permissible undefined behavior.
Sounds a bit like an oxymoron, doesn't it? After all, it is "undefined", right?
However, the C standard does exactly that!
Permissible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
(section 3.4.3)
In fact, in the first version of the ANSI/ISO C standard, this was a binding part of the standard. In later versions, it was made non-binding, though the language is still in the standard.
Yes, the standard has language that says what permissible undefined behavior is, but you are free to ignore it and still call yourself compliant. Which is what just about everybody does nowadays.
Make it binding again and most of the mess disappears.
https://blog.metaobject.com/2018/07/a-one-word-change-to-c-standard-to-make.html https://blog.metaobject.com/2018/07/a-one-word-change-to-c-s...
- jcranmer 8y agoIt doesn't fix anything. In most compilers, the behavior of compilers with respect to undefined behavior that everyone complains about boils down to "the compiler creates implicit __builtin_assumes that undefined behavior does not happen." That is "behaving during translation [...] in a documented manner characteristic of the environment," (especially given that the constant discussion of how undefined behavior is treated in the compiler by compiler writer means it's more well-documented than other mandatory-documented things, such as the actual implementation choices for implementation-defined behavior). It's just that the environment isn't the environment people thought it was.
- mpweiher 8y ago> characteristic of the environment Setting "the compiler" = "the environment" and therefore anything the compiler does is part of the environment and thus legit seems at best the type of sleight of hand the compiler writers use to justify their actions. When defining the behaviour of the compiler, "the environment" obviously cannot be "the compiler".