This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Null pointer check elimination
On Mon, Nov 14, 2005 at 04:16:43PM -0800, Janis Johnson wrote:
> On Mon, Nov 14, 2005 at 11:56:16PM +0100, Gabriel Dos Reis wrote:
> > "Michael N. Moran" <mike@mnmoran.org> writes:
> > SEGFAULT is not a behaviour defined by the language. It is *just* one
> > form of undefined behaviour. If you execute that function, it might
> > reformat your harddrive and that woud be fine -- though I know of no
> > compiler that does that on purpose. But, the point is that your
> > program in erring in the outer space.
> >
> > | // dereference: access to object
> > | // If a is null, then SEGFAULT
> > | *a = 0;
> >
> > Again, that may or may not happen.
>
> Some operating systems load a page of zeroes at address zero, so the
> dereference of a null pointer has no visible effect; a different form
> of undefined behavior. DYNIX/ptx did that by default, and I think
> that HP-UX does it. I much prefer a segfault.
(I'm about to reveal just how old I am).
Actually, there was a time when this was just the way C worked: you
got the tape from Bell Labs and ran it on your PDP-11, and people wrote
C programs that relied on *NULL returning an all-zero object (sometimes
by accident). Every C implementation in the world worked this way
at one time. It was the same on early VAX BSD releases, and then a
linker option was added to decide whether the zero page was all-zero or
inaccessible, and then SEGV became the default but the option (of an
all-zero page) was still needed to make old software work.
(We're talking 1980-82 time frame here).