Undelivered mail

MAILER%ALASKA.BITNET at CUNYVM.CUNY.EDU MAILER%ALASKA.BITNET at CUNYVM.CUNY.EDU
Sun Mar 13 07:05:51 AEST 1988


Subject:  Re: Why NULL is 0

[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 8323
          for SXJVK at ALASKA; Sat, 12 Mar 88 11:30 AST
Received: by UWAVM (Mailer X1.25) id 5618; Sat, 12 Mar 88 12:29:37 PST
Date:         Fri, 11 Mar 88 02:57:33 GMT
Reply-To:     Info-C at BRL.ARPA
Sender:       Info-C List <INFO-C at NDSUVM1>
From:         Pablo Halpern <pablo at polygen.uucp>
Subject:      Re: Why NULL is 0
Comments: To: info-c at BRL-SMOKE.arpa
To:           Vic Kapella <SXJVK at ALASKA>

>From article <10576 at mimsy.UUCP>, by chris at mimsy.UUCP (Chris Torek):
> (You may wish to save this, keeping it handy to show to anyone who
> claims `#define NULL 0 is wrong, it should be #define NULL <xyzzy>'.
> I intend to do so, at any rate.)
>
> Let us begin by postulating the existence of a machine and a compiler
> for that machine.  This machine, which I will call a `Prime', or
> sometimes `PR1ME', for obscure reasons such as the fact that it
> exists, has two kinds of pointers.  `Character pointers', or objects
> of type (char *), are 48 bits wide.  All other pointers, such as
> (int *) and (double *), are 32 bits wide.

I must admit, you have come up with a situation where the uncasted
value NULL would be an incorrect parameter to a function that didn't
have a prototype regardless of the definition of NULL. (If you missed
the original posting, please don't flame about this.  Ask someone to
mail the original to you.)  In the situation mentioned, the compiler
could not know how wide to make the null pointer when passing it to the
function.  Indeed, even with NULL defined as (void *) 0, dpANS does not
say that the size of a (void *) is the same as the size of any other
pointer.

However, if I were writing a C compiler, I would choose a size for all
pointers equal to the size of the largest possible pointer.  This would
allow code that passed uncasted NULL to work correctly, provided NULL
is a type as large as a pointer.  This is not because dpANS says it
should be so, but because so much code would break if it were not.
Perhaps ANSI should add the restriction that all pointer types must be
the same size in an effort to "codify common existing practice."



More information about the Comp.lang.c mailing list