Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Aug 2002 18:40:12 -0700 (PDT)
From:      Archie Cobbs <archie@dellroad.org>
To:        Jon Mini <mini@freebsd.org>
Cc:        obrien@freebsd.org, freebsd-arch@freebsd.org
Subject:   Re: NULL
Message-ID:  <200208210140.g7L1eCJ03992@arch20m.dellroad.org>
In-Reply-To: <20020821012849.GK3751@elvis.mu.org> "from Jon Mini at Aug 20, 2002 06:28:49 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Jon Mini writes:
> > When you say "not legal" do you mean it causes an error or a warning?
> > 
> > FYI, this question came up when porting some code to redhat Linux, where
> > NULL is defined as (void *)0.
> 
> "Not legal" refers to the fact that C is a standardised language,
> and this violates that standard. Whether or not it works in gcc is
> irrellevant.

You mean C++ right? That was the example being referred to.

> Also, NULL is defined as 0 in the standard, because this:
> 
> 	void	*p;
> 
> 	p = 0;
> 
> Is guaranteed to produce an invalid pointer, and this:
> 
> 	((p != 0) || (p == 0))
> 
> Tests for a valid pointer and an invalid pointer, respectively.

Are you saying that POSIX declares that NULL be "0"? Then I agree
we must do that.. but why then doesn't Linux?

Also, how does replacing "0" in your examples with "(void *)0"
break anything?

> The fact that pointers are linear addresses in FreeBSD and Linux
> and that the address value 0x0 is used for NULL are just some of
> the happy coincidences that the relevant standards can't rely on,
> and must define as "implementation dependant."
> 
> On a related note, this :
> 
> 	p = 1;
> 
> Is illegal.

Agreed.

> I hope this makes sense.

Sortof.. :-) 

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?200208210140.g7L1eCJ03992>