2 ms·
heh, to say that I originally wrote if(foo) and then replaced it by //... because that was not the point. Also, dereferencing an unset optional is also UB, so i
by jcelerier 7y ago
heh, to say that I originally wrote if(foo) and then replaced it by //... because that was not the point.
Also, dereferencing an unset optional is also UB, so it would segfault all the same given the same preconditions.
- paulddraper 7y agoYes. The code is equivalent, but it's clear that the second is meant to optional. The first has no such indication, except hopefully some human-readable comment that the pointer may be NULL.
- jcelerier 7y ago> The first has no such indication, except hopefully some human-readable comment that the pointer may be NULL. I don't understand. If the parameter was not meant to be sometimes null it would be a reference; not a pointer. The fact that a pointer is used is the "this may be null" indication.