Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: NULL pointers Message-ID: <4375@mimsy.UUCP> Date: Fri, 21-Nov-86 12:02:46 EST Article-I.D.: mimsy.4375 Posted: Fri Nov 21 12:02:46 1986 Date-Received: Fri, 21-Nov-86 22:02:28 EST References: <1696@ncoast.UUCP> Reply-To: chris@mimsy.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 38 In article <1696@ncoast.UUCP> kent@ncoast.UUCP (Kent Williams) writes: >... the use of NULL is a constant source of pain for which >it seems there is a simple solution to wit > >#ifdef HASVOID >#define NULL ((void *)0) >#else >#define NULL 0L >#endif This is neither necessary nor sufficient: >If NULL is typed to have the size of the largest possible object that it >will be assigned to, it will be 'narrowed' to fit into whatever object you >are assigning it to. If you are using `0' (the present proper definition for NULL) in an assignment or comparison context, the narrowing or widening or implicit cast conversion or whatever-is-required is done automatically. If you are using 0 in some other context, the information as to just what narrowing or widening or implicit cast conversion or whatever-is-required is unavailable. It is not difficult to add an assignment context by using an explicit cast: foo((char *) NULL); /* or foo((char *) 0); */ In C++, or some other C-like language with function prototypes, the prototype can provide the context: extern void foo(char *s); ... foo(NULL); /* or foo(0); */ In either case, an explicit cast is still legal, and may help the reader as well as the compiler. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu