Path: utzoo!mnetor!uunet!steinmetz!davidsen From: davidsen@steinmetz.steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Why NULL is 0 Message-ID: <10229@steinmetz.steinmetz.ge.com> Date: 4 Apr 88 16:22:19 GMT References: <2550049@hpisod2.HP.COM> <7412@brl-smoke.ARPA> <3351@chinet.UUCP> <10574@mimsy.UUCP> <10576@mimsy.UUCP> <636@acer.stl.stc.co.uk> <963@micomvax.UUCP> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric CRD, Schenectady, NY Lines: 37 There has been a great deal of misunderstanding of the use of zero and pointers. It seems clear in K&R and practice that assignment of a zero to a pointer produces a NULL pointer of the appropriate type. What is incorrectly assumed is that zero *is* a NULL pointer. People (usually ;>) have no problem with the idea the while assigning a zero to a float gives it the vaule 0.0, in most implementations the float value does not have all bits set to zero. There are two places in which a zero will not work as expected: In expressions, adding an int expression to a pointer produces a pointer result, while adding an int expression to an int constant (zero) produces an int result. Since there does not seem to be a good use for treating the sum of two ints an address in any remotely portable program, this is of interest but not concern. In procedure calls, however, on many machines the arguments must have the correct type for portability because either the size of int and pointer are not the same, or because the size and content of various pointer types are not the same. If prototypes are used, then coding need not be as precise, since use of 0 where 0L is needed, or zero where (char *)0 is needed will be corrected by the compiler. Without prototypes the arguments will need to be correct if the program is to be portable. There are many programs which "have worked for years" which are not portable, because of this lack of typing on arguments. Most of these run on any machine which has the size of int equal sizeof pointer, and all pointers are the same in content. This includes the VAX and 68000 family. Other machines, such as some Data General models, Cray, small Intel processors, SPARC, and some non-UNIX C compilers on any machine will not accept this lack of explicit typing. -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs | seismo}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me