Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!MAILER%ALASKA.BITNET@CUNYVM.CUNY.EDU From: MAILER%ALASKA.BITNET@CUNYVM.CUNY.EDU Newsgroups: comp.lang.c Subject: Undelivered mail Message-ID: <12249@brl-adm.ARPA> Date: 12 Mar 88 00:23:03 GMT Sender: news@brl-adm.ARPA Lines: 54 Subject: Re: Header problems [Non-Deliverable: User does not exist or has never logged on] Reply-To: Info-C@BRL.ARPA Received: From UWAVM(MAILER) by ALASKA with Jnet id 5172 for SXJVK@ALASKA; Fri, 11 Mar 88 15:02 AST Received: by UWAVM (Mailer X1.25) id 3419; Fri, 11 Mar 88 16:00:18 PST Date: Wed, 9 Mar 88 17:20:17 GMT Reply-To: Info-C@BRL.ARPA Sender: Info-C List From: Alan J Rosenthal Subject: Re: Header problems Comments: To: info-c@brl-smoke.arpa To: Vic Kapella Doug Gwyn wrote about NULL, and said that the proper definition of it is ``#define NULL 0''. dag@chinet.UUCP (Daniel A. Glasser) wrote: >Your use of NULL === 0 promotes unportable code ... [moralizing deleted] > >On machines were sizeof int != sizeof(void *), the above definition will >not work on older style function calls (without prototypes) or in var-arg >situations. Requiring sizeof int == sizeof(void *) is not a viable >solution... > > #define NULL ((void *)0) >On older compilers, replace 'void' with 'char'. This allows the use of >a short NULL representation when the compiler is smart enough to use it >but forces passing of NULL in argument lists as a pointer sized object. This doesn't require sizeof(int) == sizeof(void *). The assumption is that you always cast NULL before passing it. Casting is still required if NULL is defined as ((void *)0); you can't assume that all pointers have the same size or representation. Passing a pointer to void to a routine that expects a pointer to struct gosh is as big a mistake as passing an int to a routine that expects a pointer to struct gosh. By the way, if you call f(0) where f expects a char *, the requirement for it to work is not simply that sizeof(int) == sizeof(char *), but also that (int)0 and (char *)0 have the same bit representation. With respect to your phrase "a pointer sized object" - there is no such thing in C. There may happen to be such a thing in a particular implementation of C due to hardware considerations. (Obviously, it is usually advantageous to represent all pointers in the same way (but not always); therefore this is a common occurrence.) ajr -- If you had eternal life, would you be able to say all the integers?