comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: Look what I caught! was re:Ada paper critic
Date: Wed, 19 Jun 2002 17:11:01 GMT
Date: 2002-06-19T17:11:01+00:00	[thread overview]
Message-ID: <FW2Q8.893$iG4.643@nwrddc04.gnilink.net> (raw)
In-Reply-To: 3D10952F.17A62CCF@despammed.com

Actually, what the C standard says is that if you have a pointer just after
the end of an array, then the result of dereferencing that pointer is
"unpredictable". Such dereferences can cause segmentation fault, trash some
other memory, or do nothing at all. Any of these outcomes is consistent with
the standard. It's up to the programmer to avoid this behaviour.

Really, all the standard requires is that the compiler can generate a
pointer (not a corresponding object!) just past the right end of the array.
In others words, if we define

    PLANET solar_system[ 9 ];
    PLANET *past_pluto = solar_system + 9;

Then all the standard requires is that past_pluto can be computed, and that
it will compare correctly with pointers to other elements in solar_system,
e.g.

    ( past_pluto > solar_system + 0 ) &&
    ( past_pluto > solar_system + 1 ) &&
    ( past_pluto > solar_system + 2 ) &&
    ...
    ( past_pluto > solar_system + 8 )

That's all that's required. Access *past_pluto, and you're on your own.

Also, the standard only requires a valid pointer to the point just after the
end of an array; no similar rule applies to the beginning of the array. For
example, if you declare

    PLANET *before_mercury = solar_system - 1;

then the standard does NOT require that before_mercury compare meaningfully
with the addresses of the solar_system elements. Of course, the result of
dereferencing before_mercury is unpredictable.





  parent reply	other threads:[~2002-06-19 17:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-17 17:35 Look what I caught! was re:Ada paper critic Alderson, Paul A.
2002-06-17 18:31 ` Darren New
2002-06-17 21:40 ` Vinzent Hoefler
2002-06-17 23:14   ` Darren New
2002-06-18 14:49     ` Hyman Rosen
2002-06-18 22:36     ` Vinzent Hoefler
2002-06-18 13:28   ` Marin David Condic
2002-06-24 19:17     ` Vinzent Hoefler
2002-06-18 19:16   ` Kevin Cline
2002-06-18 22:36     ` Vinzent Hoefler
2002-06-19 14:29       ` Wes Groleau
2002-06-19 16:59         ` Darren New
2002-06-19 17:48           ` Wes Groleau
2002-06-19 17:56             ` Darren New
2002-06-19 17:11         ` Frank J. Lhota [this message]
2002-06-19 19:31           ` Robert A Duff
2002-06-19 20:02             ` Hyman Rosen
2002-09-24 15:23               ` Matthew Heaney
2002-06-19 19:37         ` Robert A Duff
2002-06-19 13:52 ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox