4 ms·
True -- but how does that affect the semantics? Both definitions say that undefined behavior can be dealt with by "ignoring the situation completely with unpre
by _kst_ 3y ago
True -- but how does that affect the semantics?
Both definitions say that undefined behavior can be dealt with by "ignoring the situation completely with unpredictable results". There are no restrictions on what can happen.
(The standard joke is that it can make demons fly out of your nose. Of course that's not physically possible, but it would not violate the standard.)
- mpweiher 3y agoIgnoring ≠ taking action based on The standard joke is a joke, because it is wrong.
- nlewycky 3y ago> The standard joke is a joke, because it is wrong. No, it is a joke because it is silly. It is correct and intended for pedagogy.
- muldvarp 3y ago> The standard joke is a joke, because it is wrong. No, it's a joke because it's _physically_ impossible but allowed. That said, clang and gcc are of course not antagonistic and don't make use of UB to anger their users. Instead, they make use of UB to aggressively optimize (valid) programs, which is important because C is used for a lot of high-performance code where every bit of optimization can save a lot of time and money. The fact that this sometimes leads to invald programs (i.e. programs with no defined behavior according to the standard) being optimized to correct but "absurd" results is just a trade-off compiler writers like to take. Mostly because such programs are erroneous anyway, even under a strict "portable assembler" view, which again the standard does not enforce (or even encourage).
- deleted 3y ago[deleted]