Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Aug 2002 18:01:00 -0700 (PDT)
From:      Archie Cobbs <archie@dellroad.org>
To:        obrien@freebsd.org
Cc:        freebsd-arch@freebsd.org
Subject:   Re: NULL
Message-ID:  <200208210101.g7L110m03801@arch20m.dellroad.org>
In-Reply-To: <20020821002116.GA33223@dragon.nuxi.com> "from David O'Brien at Aug 20, 2002 05:21:16 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
David O'Brien writes:
> > Simple question...
> > Why isn't NULL defined to be "((void *)0)" instead of "0" ?
> 
> In C++ this is not legal:
> 
>     void blah(void) {
>         int *foo;
>         void *bar;
>         bar = foo;
>         foo = bar;
>     }
> 
> it is in C, but we share the definition.
> A benefit of "(void *)0" is that this would be caught:
> 
>     char c = NULL;
> 
> rather than the correct:
>     char c = '\0';
> 

When you say "not legal" do you mean it causes an error or a warning?

If it's just a warning, then are you saying the reason we don't use
(void *)0 is because we would lose the C++ warning to gain the C warning?
Seems like a fair trade to me :-)

FYI, this question came up when porting some code to redhat Linux, where
NULL is defined as (void *)0.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208210101.g7L110m03801>