Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!vax135!cornell!uw-beaver!tektronix!reed!alexis From: alexis@reed.UUCP (Alexis Dimitriadis) Newsgroups: net.lang.c Subject: Re: NULL pointer Message-ID: <2158@reed.UUCP> Date: Tue, 19-Nov-85 00:27:15 EST Article-I.D.: reed.2158 Posted: Tue Nov 19 00:27:15 1985 Date-Received: Wed, 20-Nov-85 00:53:13 EST References: <2098@brl-tgr.ARPA> <916@celtics.UUCP> <2910@sun.uucp> <52@hadron.UUCP> <2982@sun.uucp> <325@steinmetz.UUCP> Reply-To: alexis@reed.UUCP (Alexis Dimitriadis) Organization: Reed College, Portland, Oregon Lines: 33 Summary: > #define NULL ((char *) 0) > > rather than arithmetic zero. This would make it work on machines which use a > non-zero null pointer. I have tried doing this in a number of programs to > examine the effect on lint and/or the generated code, and have yet to find a > case where it caused a problem (although it did reveal a few genuine bugs in > "working code"). What exactly did you try? Defining NULL this way generates _compiler_ errors whenever you use NULL in a context that requires anything other than a char pointer, e.g. a comparison. The only case when it _fixes_ things is when NULL is a function argument, and the draft standard will provide for function argument coercion, as well. Example: #include #undef NULL #define NULL ((char *)0) main() { if (fopen("foo", "w") == NULL) ; } % cc t.c "t.c", line 8: warning: illegal pointer combination --Alexis Dimitriadis -- _______________________________________________ As soon as I get a full time job, the opinions expressed above will attach themselves to my employer, who will never be rid of them again. alexis @ reed {decvax,ihnp4,ucbcad,uw-beaver}!tektronix!reed.UUCP