Xref: utzoo comp.arch:4914 comp.lang.c:10251 Path: utzoo!utgpu!water!watmath!clyde!att!alberta!calgary!radford From: radford@calgary.UUCP (Radford Neal) Newsgroups: comp.arch,comp.lang.c Subject: Re: negative addresses (real C null pointers) Message-ID: <1618@vaxb.calgary.UUCP> Date: 19 May 88 21:45:10 GMT References: <2393@uvacs.CS.VIRGINIA.EDU> <21541@amdcad.AMD.COM> <10001@tekecs.TEK.COM> Organization: U. of Calgary, Calgary, Ab. Lines: 39 In article <10001@tekecs.TEK.COM>, andrew@frip.gwd.tek.com (Andrew Klossner) writes: > >> Unfortunately, it is a real problem, because there are zillions of > >> programs that implicitly assume that [null] pointers are all-zeros. > > > I don't think this is true. How about an example? > > Sure Doug, from the system V kernel... In routine ttout: > > if (tbuf->c_ptr) My understanding is that this is standards-conforming and portable. I assume that c_ptr is declared to be of pointer type. The above statement is equivalent to if (tbuf->c_ptr!=0) which is equivalent to if (tbuf->c_ptr!=(char*)0) (or (int*)0 or whatever). The expression (char*)0 is _defined_ to be the null pointer, whatever its bit pattern may be. Note that "NULL" has nothing to do with anything, being merely a macro found in the include file. An example of a non-portable program is the following: char *p; int i; ... i = (int)p; if (i!=0) *p = ...; /* no guarantee that p is not null... */ Only occurences of 0 in the explicit or implicit context (...*) 0 are magically converted to null pointers. Radford Neal