Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!shopiro From: shopiro@alice.UUCP (Jonathan Shopiro) Newsgroups: comp.lang.c++ Subject: Re: references to dereferenced null pointers Summary: When is a pointer dereferenced (it matters in C++) Message-ID: <10582@alice.UUCP> Date: 16 Mar 90 15:25:26 GMT References: <51083@microsoft.UUCP> <25EB8EE8.8462@paris.ics.uci.edu> <16179@haddock.ima.isc.com> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 56 To me the interesting question in this null pointer business is whether there is any circumstance where it is legal to say *p where p is a null pointer. For example, it is definitely legal to write void f(int* p) { if (p == 0) ... } int* x = 0; f(x); It is not obvious (to me) if it is legal in C to write void g(int* p) { if (&(*p) == 0) ... } int* x = 0; g(x); But nobody would write that code anyway, so who cares. However, in C++ there is an analog that is very likely to be written. void h(int& r) { if (&r == 0) ... } int* x = 0; h(*x); It seems to me that g() and h() are two ways of writing the same thing. I think it would be nice if they were both legal. I think the fundamental issue here is when is a pointer dereferenced? (Since it is clearly illegal to dereference the null pointer). I don't se why writing *p alone, or &*p should dereference p. -- Jonathan Shopiro AT&T Bell Laboratories, Warren, NJ 07060-0908 research!shopiro (201) 580-4229