logoalt Hacker News

aw1621107 • yesterday at 4:30 AM • 1 reply • view on HN

> While they help avoid this, because of the way C++ behaves it may result in a null object as well, so a run-time check is still needed.

I think the difference is that with references you can only perform such a check before you create the reference. Pretty sure optimizers can and will elide checks for null references.


Replies

locknitpicker • yesterday at 6:52 AM

> I think the difference is that with references you can only perform such a check before you create the reference. Pretty sure optimizers can and will elide checks for null references.

As someone who had the displeasure of maintaining a decades-old legacy project that had references initialized and assigned with NULL, I don't agree.

➕ show 1 reply