3 ms·
In C++, null references are Very Bad, and they trigger undefined behavior: https://stackoverflow.com/questions/4364536/is-null-reference-possible https://stacko
by ekidd 9y ago
In C++, null references are Very Bad, and they trigger undefined behavior: https://stackoverflow.com/questions/4364536/is-null-reference-possible https://stackoverflow.com/questions/4364536/is-null-referenc...
I don't think I've ever run into a null reference in the real world. I'm sure it happens, especially if people write "&*some_function_that_might_return_null()". But it shouldn't be a normal thing. There are lots of other issues with C++, but this has never been a major one in my experience.
- imron 9y ago> In C++, null references are Very Bad, They are! And while they are not a normal thing, they are a thing and I've run in to them a handful of times in the real world, almost always the result of someone not checking for null before dereferencing a pointer. Rust does not really have this issue.
- pjmlp 9y agoRust also has this issue, unless you fully validate every single pointer coming out of unsafe blocks.
- imron 9y agoThe difference being that all c++ code is 'unsafe' in the rust sense, whereas a typical rust program will have only a small portion of unsafe code (or none), making it easier to fully validate - hence 'doesn't really have this problem'.
- pjmlp 9y agoI agree, but it depends how seriously unsafe blocks get reviewed. Because I can assure you, unsafe blocks in enterprise Rust will be reviewed as much as C and C++ code currently are in most Big Corps™. We do have such problems with native libraries killing Java and .NET processes, with unsafe being the FFI boundary.