Re:Zig: software should be perfect [video]
by masklinn on Sunday November 11, 2018 @06:53AM
(#18425979)
> Well, you're in luck then! You don't even need a 'modern' successor, C++ (even the ancient versions) disallow null references.
That's useful, until you realise that all its smart pointers are semantically nullable (they can all be empty with the same result as a null raw pointer) and then nothing's actually fixed.
Re:Zig: software should be perfect [video]
by Mesopropithecus on Sunday November 11, 2018 @04:37AM
(#18425613)
What you mean is that C++ doesn't have a way to (easily) let you check whether a given reference is null or not. int* a = NULL; int& b = *a; compiles and runs just fine.
Re:Zig: software should be perfect [video]
by masklinn on Sunday November 11, 2018 @06:52AM
(#18425976)
> compiles and runs just fine.
For fairly low values of those. Creating a null reference is UB, your program is not legal at all.
Re:Zig: software should be perfect [video]
by coldtea on Sunday November 11, 2018 @08:26AM
(#18426258)
If the compiler still accepts it, then that it belongs to the "UB" class of code is not much comfort.
The whole point is to NOT have it be accepted.
Re:Zig: software should be perfect [video]
by jessaustin on Sunday November 11, 2018 @08:10AM
(#18426196)
Sure, we're not supposed to do that. Sometimes it happens anyway, and the C++ compiler isn't much help in that case.
Re:Zig: software should be perfect [video]
by ethan_g on Sunday November 11, 2018 @06:58AM
(#18425989)
No the gp is correct, references in c++ can't be null. Your code invoked undefined behavior before you did anything with a reference, namely *a which is a null pointer dereference.
Re:Zig: software should be perfect [video]
by the_why_of_y on Sunday November 11, 2018 @07:39AM
(#18426105)
> namely *a which is a null pointer dereference.
Which is a textbook example of the null reference problem.
Edit: There may be some terminological confusion here: when programming language folks talk about "references", they include in that definition what C/C++ call "pointers". See for example the Wikipedia article, which gives as the C++ example not C++ references, but C++ pointers.
Well, you're in luck then! You don't even need a 'modern' successor, C++ (even the ancient versions) disallow null references.