Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!uwvax!oddjob!gargoyle!mason From: mason@gargoyle.UChicago.EDU (Tony Mason) Newsgroups: comp.lang.c Subject: Re: pointer debate raging on... Message-ID: <636@gargoyle.UChicago.EDU> Date: Tue, 28-Apr-87 12:28:39 EDT Article-I.D.: gargoyle.636 Posted: Tue Apr 28 12:28:39 1987 Date-Received: Thu, 30-Apr-87 01:04:58 EDT References: <149@sds.UUCP> <31@thirdi.UUCP> <6479@mimsy.UUCP> Reply-To: mason@gargoyle.uchicago.edu.UUCP (Tony Mason) Organization: U. of Chicago, Computer Science Dept. Lines: 43 Keywords: pointers, religion, sin, Ritchie, razor blades, etc. In article <6479@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >In article <31@thirdi.UUCP> peter@thirdi.UUCP (Peter Rowell) writes: >>As pointed out, environments where sizeof(int) != sizeof(char *) >>require NULL to be define'd as ((char *)0) (or some variation on that >>theme). > >This is not true. NULL can be, and indeed, in K&R C, NULL *must* >be, defined as 0. Perhaps someone is confusing 0 the int, to 0 the NULL pointer symbol? K & R seem to make a distinction here: (p.192, K&R) "The compilers currently allow a pointer to be assigned to an integer, an integer to a pointer, and a pointer to a pointer of another type. The assignment is a pure copy operation, with no conversion. This usage is nonportable, and may produce pointers which cause addressing exceptions when used. However, it is guaranteed that assignment of the constant 0 to a pointer will produce a null pointer distinguishable from a pointer to any object." They DON'T say the "integer 0" but rather the "constant 0". This must be considered a context sensitive problem that a compiler designer must take into account. Equally, though, K & R don't explicitly say NULL *must* be defined as 0. Indeed, I have had problems with this area before and don't use NULL much anymore, as I have seen systems where NULL came DEFINED (from the distribution) as (char *)0. It did make code break. Thus, the safest thing to do is use 0. Not the integer, but the constant. For those who don't trust compiler writers to stay up to spec, you can use (char *)0, (int *)0, etc. There has been a traditional attitude of laxness in the UNIX environment. I have cursed at VAX writers who assume that a long was an int (case statements break when used with ANYTHING besides ints.) It is only the largess of compiler writers that allowed this type of behavior. Tony Mason Univ. of Chicago, Dept. of C.S. ARPA: mason@gargoyle.uchicago.edu UUCP: ...ihnp4!gargoyle!mason