Xref: utzoo comp.lang.c++:6801 comp.std.c:2605 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.lang.c++,comp.std.c Subject: Re: references to dereferenced null pointers Message-ID: <3029@auspex.auspex.com> Date: 13 Mar 90 18:50:20 GMT References: <25F8D2FB.10981@paris.ics.uci.edu> <1990Mar11.015305.28264@utzoo.uucp> <1990Mar11.222634.2701@almira.uucp> Followup-To: comp.std.c Organization: Auspex Systems, Santa Clara Lines: 44 > I beg to differ. I see where you are coming from with the wording: >"an integral constant expression with the value 0", but in K&R First edition, >page 97, there is an explicit example which 0 is returned by a function >returning a pointer to a character. Since the compiler knows that the function is supposed to return a "char *", the compiler knows that the integral constant with the value 0 being returned by that function should be converted to a null pointer-to-char. In other words, said function doesn't return an integral value of 0, it returns a null pointer-to-char. This conversion is no different from the conversion in char *p; p = 0; or extern void foo(char *p); foo(0); or char *p; if (p == 0) ... or even char *p; if (!p) /* equivalent to previous example */ ... The same applies to: >Also, from the text "C guarantees that no >pointer that validly points at data will contain zero, so a return value of >zero can be used to signal an abnormal event,..." since if your function returns a pointer value, it had better be defined as doing so....