4 ms·
> I don't get this "undefined behavior" cliche. The problem is that you can do everything in portable C that you can do with undefined behavior in C, and often
by sedachv 9y ago
> I don't get this "undefined behavior" cliche.
The problem is that you can do everything in portable C that you can do with undefined behavior in C, and often in a more straightforward fashion.[1] The compiler won't tell you that you are doing it wrong; there are many examples, tutorials, and books that encourage you to do the wrong thing. The undefined behavior will work until you switch to a different system. Why allow the wrong thing to continue to happen?
[1] A very good example of this is endianness:
https://news.ycombinator.com/item?id=16189110 https://news.ycombinator.com/item?id=16189110
https://commandcenter.blogspot.se/2012/04/byte-order-fallacy.html https://commandcenter.blogspot.se/2012/04/byte-order-fallacy...
- fjsolwmv 9y agoYou are conflating undefined with implementation defined. If you use undefined behavior the compiler might simply delete your code since it's not defined.
- sedachv 9y agoYou and a lot of people in this discussion seem confused the other way. The amount of things in C that are implementation-defined is relatively small and most has to do with character encodings and byte size (storage unit). The kind of behavior people are pointing to is definitely labeled as undefined, and there is a lot of it. Take a look at Harbison and Steele for example.