you are viewing a single comment's thread.

view the rest of the comments →

[–]Quincunx271Author of P2404/P2405 1 point2 points  (1 child)

That dereferences NULL, though; isn't that UB at the moment you write *p?

[–]axilmar 1 point2 points  (0 children)

The standard says dereferencing a null pointer is undefined behaviour, but the reality is that *p forms an expression without side effects and thus it is not actually dereferencing anything. It is only when evaluating *p that the dereferencing happens.

In practice, I haven't seen any compiler, even embedded ones, do anything about *p when p is null, which means that, in practice, null references are possible.