Undelivered mail

MAILER%ALASKA.BITNET at CUNYVM.CUNY.EDU MAILER%ALASKA.BITNET at CUNYVM.CUNY.EDU
Sat Mar 12 10:23:03 AEST 1988


Subject:  Re: Header problems

[Non-Deliverable:  User does not exist or has never logged on]

Reply-To: Info-C at BRL.ARPA

Received: From UWAVM(MAILER) by ALASKA with Jnet id 5172
          for SXJVK at 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 at BRL.ARPA
Sender:       Info-C List <INFO-C at NDSUVM1>
From:         Alan J Rosenthal <flaps at dgp.toronto.EDU>
Subject:      Re: Header problems
Comments: To: info-c at brl-smoke.arpa
To:           Vic Kapella <SXJVK at ALASKA>


Doug Gwyn <gwyn at brl.arpa> wrote about NULL, and said that the proper
definition of it is ``#define NULL 0''.

dag at 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?



More information about the Comp.lang.c mailing list