Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!dayton!viper!john From: john@viper.UUCP (John Stanley) Newsgroups: news.software.b,comp.lang.c Subject: Re: News for Xenix on PC AT ? Message-ID: <888@viper.UUCP> Date: Fri, 24-Apr-87 15:42:21 EST Article-I.D.: viper.888 Posted: Fri Apr 24 15:42:21 1987 Date-Received: Sun, 26-Apr-87 01:12:17 EST References: <18346@ucbvax.BERKELEY.EDU> <145@sds.UUCP> <17005@sun.uucp> <146@sds.UUCP> <5787@brl-smoke.ARPA> Reply-To: john@viper.UUCP (John Stanley) Organization: DynaSoft Systems Lines: 58 Xref: mnetor news.software.b:539 comp.lang.c:1884 In article <5787@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: > >He, I, and others have explained more than once before in the C newsgroup >that the only fully correct definition of the macro NULL, as C now stands, >is as 0. (Under the proposed ANSI standard you could probably get away >with defining it as (void *)0.) > Actualy, you -must- use (void *)0 -OR- 0 and be consistant one way or the other. It's not an option... If I had to choose, I'd say use #define NULL ((void*)0) because it's used as a pointer in 98% of the code I've seen and for the following reason... This isn't important on machines where sizeof(pointer) == sizeof(int), but if you're using (as a simple example) a machine where pointers are 32 bit and ints are 16 bits then code containing the following function may have problems if you change how NULL is defined: char *myfunc(ind, str, ind2) int ind, ind2; char *str; { char mystr[80]; if (str == NULL) str = mystr; ...... some code ..... return (str); } now, later in my program if I have NULL defined as 0, then the following line will cause the wrong number of bytes to be pushed on the stack: myfunc( i1, NULL, i2 ); If you use NULL as a pointer, it -must- always actualy be a pointer or your code will break any time you try to pass it as a constant to a function. You may claim, if you wish, that passing NULL as a constant is illegal, but I've seen too many examples of code where it's been done to accept that as a valid argument. If there already exists a large body of code using a particular construct, then that construct may be "illegal" in your opinion, but anyone discussing "the only fully correct definition" must take it into account... --- John Stanley (john@viper.UUCP) Software Consultant - DynaSoft Systems UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john