3 ms·
> In C89, undefined behavior is interpreted as, “The C standard doesn’t have requirements for the behavior, so you must define what the behavior is in your impl
by kazinator 4y ago
> In C89, undefined behavior is interpreted as, “The C standard doesn’t have requirements for the behavior, so you must define what the behavior is in your implementation, and there are a few permissible options”
That is flat out wrong; it describes implementation-defined behavior, not undefined-behavior.
In spite of the word "permissible", the range of what is permissible is very broad. It is permissible to "ignor[e] the situation completely, with unpredictable results". Ignore the situation means not to implement any requirements at all in regard to that situation, and not provide a shred of documentation about that. (Contrary to the article's claim.)
Nowhere is it imposing a requirement for the implementation to define any choices. Only one of the options refers to documentation: in some area where behavior isn't defined, the implementors can choose to provide a documented extension. It's that documentation which makes it an extension. If the documentatio isn't provided, then the behavior isn't a documented extension. There is no requirement one way or the other.
Now about this "permissible" versus "possible" difference: there could be one, but perhaps not in the way the article's author thinks.
When C89 says that it's permissible to ignore the situation, that seems to rules out malice. If the program perpetrates the undefined situation, and some harm occurs (like a flash partition being wiped out), that must have happened because the situation had been ignored with unpredictable consequences, and not because the implementor put in code to detect the instance of undefined behavior, and arranged for the erasure to be done on purpose.
"Permissible" seems to be encouraging the implementor to terminate the program (possibly with a diagnostic) if the implementor develops the ability to detect the situation. Detecting the situation and acting maliciously is not in the range of what is "permissible".
With the word "possible", it is less clear that malice is being discouraged. Clearly, malice is not logically impossible; it seems as if the word is introducing an inexhaustive list of example consequences.