3 ms·
In C++ (specifically) one can limit oneself to using safe constructs provided by the standard library. (C is a different story, of course.)
by Koshkin 2y ago
In C++ (specifically) one can limit oneself to using safe constructs provided by the standard library. (C is a different story, of course.)
- xscott 2y agoI think somebody could write a safe C++ library, but the STL hands out dangling references like candy at Halloween. It's very easy to get use-after-free problems with it.
- Koshkin 2y agoI don't know what you are talking about. (What I meant was, the need for pointer arithmetic can be avoided by using iterators, and use-after-free, by using smart pointers.)
- xscott 2y ago> I don't know what you are talking about. I can see that. Iterators don't do what you think they do. A random access iterator on std::vector is practically indistinguishable from a pointer. It doesn't check for out of bounds, and if you resize the vector, your iterator can be "invalidated", meaning it quietly points to memory that has been freed already. You can even do arithmetic on random access iterators the way you do with pointers. I agree that smart pointers are nice.