3 ms·
I just read the C++ Primer because I wanted to hack on some C++ code and the number of things you can do in C or C++ that result in "undefined behavior" is anno
by narrator 9y ago
I just read the C++ Primer because I wanted to hack on some C++ code and the number of things you can do in C or C++ that result in "undefined behavior" is annoyingly large. There are some functions where they could have added a bounds check to the implementation, but the whole philosophy of the language seems to be that when choosing between lack of bult-in checks that would lead to easy to make errors that would cause undefined behavior and small speed increases on microbenchmarks the language designers choose the latter.
- maxlybbert 9y agoFor what it's worth, in Design and Evolution of C++, Stroustrup says that when he was designing features, he would often think of a simple rule that he couldn't enforce (e.g., "couldn't enforce" being "if you violate this rule, the results are undefined") and a complex rule that he could enforce. He generally tried to pick the simpler, easier to teach rule. Unfortunately, that means there's more undefined behavior if those simpler rules are violated.