Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C++, null references are Very Bad, and they trigger undefined behavior: 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.



> 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.


Rust also has this issue, unless you fully validate every single pointer coming out of unsafe blocks.


The 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'.


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: