Xref: utzoo comp.arch:4886 comp.lang.c:10217 Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pasteur!agate!ig!uwmcsd1!marque!gryphon!sarima From: sarima@gryphon.CTS.COM (Stan Friesen) Newsgroups: comp.arch,comp.lang.c Subject: Re: negative addresses Message-ID: <4086@gryphon.CTS.COM> Date: 19 May 88 00:36:08 GMT References: <2393@uvacs.CS.VIRGINIA.EDU> <21541@amdcad.AMD.COM> <1988May12.162906.16901@utzoo.uucp> <7881@brl-smoke.ARPA> <10001@tekecs.TEK.COM> Reply-To: sarima@gryphon.CTS.COM (Stan Friesen) Organization: Trailing Edge Technology, Redondo Beach, CA Lines: 49 In article <10001@tekecs.TEK.COM> andrew@frip.gwd.tek.com (Andrew Klossner) writes: >Doug Gwyn (gwyn@brl-smoke.ARPA) writes: > >> I don't think this is true. How about an example? [[Of code assuming the null pointer is all zero bits]] > >Sure Doug, from the system V kernel that you defend so ardently :-), >file io/tt1.c (vanilla release 3.1): > > if (tbuf->c_ptr) > > if (tbuf->c_ptr == NULL) > > if (tp->t_rbuf.c_ptr) { > if (tp->t_tbuf.c_ptr) { > >The C standards I've seen so far are pretty clear in stating that the >conditional is compared against zero. There doesn't seem to be leeway >to define pointer comparisons to be against some non-zero NULL value. Yes, but they ALSO require that comparing a NULL-pointer to zero evaluate to true *whatever* the representation of the NULL-pointer. The compiler is *also* required to convert the integer constant 0 to the NULL-pointer on assignment. So *none* of the above examples assume anything about the representation of the NULL-pointer, they are all strictly conforming. There *are* cases of code that does make such assumptions. They all have the following general form: func1(p) char *p; { /* stuff */ } ... func2() { ... func1(0); } In this example the code assumes both the representation *and* the size of NULL-pointer. This code is *not* portable even among existing compilers. Nor is it even conforming, let alone strictly so. Any code of this form only works accidentally and needs to be fixed anyway. -- Sarima Cardolandion sarima@gryphon.CTS.COM aka Stanley Friesen rutgers!marque!gryphon!sarima Sherman Oaks, CA