Reply to post:

Keep calm and learn Rust: We'll be seeing a lot more of the language in Linux very soon

Anonymous Coward
Anonymous Coward

[ ...] to describe null references

There are no null references. Not in C, and not in C++.

There are no references in C. Period.

There are references in C++, but they cannot be null. As per the C++ Standard.

// nulref.cpp

int main()

{

int& r = nullptr;

return 0;

}

>> g++ -g -O2 -std=c++17 -c nulref.cpp

nulref.cpp: In function ‘int main()’:

nulref.cpp:3:12: error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘std::nullptr_t’

3 | int& r = nullptr;

Preempting:

You can change the declaration

int& r = nullptr;

to

const int& r = nullptr;

all you want. Still the same. Null references are not allowed, and do not exist in C++.

You can have null pointers. A pointer is not a reference, and a reference is not a pointer.

But you're an expert.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon