52 ms·
The problem with "Safe C++", is you immediately hit unsafe behaviour as soon as you write v[x] for a C array, std::array, or std::vector.
by CJefferson 4y ago
The problem with "Safe C++", is you immediately hit unsafe behaviour as soon as you write v[x] for a C array, std::array, or std::vector.
- netr0ute 4y agoThen just don't do that, because v.at(x) does exactly the same thing and is safe and requires a whopping 3 characters more to type.
- CJefferson 4y agoYes, but that is one of many, many small things you have to remember and never get wrong. I wonder how many C++ code bases never use v[x] on containers where it is undefined behaviour to go out of bounds? I've not seen one myself.
- saghm 4y agoLiterally all UB is avoidable if you just "don't do" the things that cause it, and yet it still happens all the time. You might be right that this specific source of UB might not be a large issue in practice, but there are so many different causes of it that overall the strategy of "just don't write code that causes UB" is empirically not effective at scale.