comp.lang.ada
 help / color / mirror / Atom feed
From: "David Thompson" <david.thompson1@worldnet.att.net>
Subject: Re: Commercial C To Ada 95 compiler
Date: Fri, 21 Jun 2002 17:23:15 GMT
Date: 2002-06-21T17:23:15+00:00	[thread overview]
Message-ID: <7iJQ8.47608$LC3.3639376@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 3D076BFC.92A8F9C5@san.rr.com

Darren New <dnew@san.rr.com> wrote :
> Marin David Condic wrote:
> >
[ about C:  int * p = array; p++; p++; etc. ]
> > Unless my intent was to figure out the address of the thing located just
> > after X - probably Y in this case.
>
> You're allowed to go one past the end in either direction. You're not
> allowed to go two past the end.
>
To be really precise, in Standard/portable C you are allowed to
compute the address (pointer) one-past-the-(right-)end, but not
dereference it.  This allows the common idiom (dating from
before standardization):
  for( p = array; p < array+n; p++ ) do_something_with(*p);
  /* and all variants/isomorphs thereof */

You cannot safely even compute array-1 or array+N+1.
In C89 in theory you cannot even use &array[N] instead of
array+N, because in the abstract semantics this actually
dereferences to form the lvalue before taking its address.
In practice all compiles actually implement &*(array+n)
as array+n and this works because of the memory layout
requirements above, and C99 adds an explicit blessing.

> > The thing is that it isn't really an
> > error until you are trying to de-reference the thing pointed to by Y.
>
> This is what I'm saying. No, that's theoretically incorrect. It *is* an
> error even if you don't try to dereference the thing pointed to by Y. Simply
> doing the arithmetic on Y is in theory erroneous.
>
Right.  As above.

> > Before
> > that its just incrementing a counter - which might be done for all sorts of
> > reasons none of which may have anything to do with the array X.
>
> Well, no, it's incrementing a pointer into the array X. If you were talking
> about using array subscripting, that would be true. But if you're talking
> about incrementing pointers rather than integers, the hardware is allowed to
> enforce (for example) segments of exactly the right size, such that a
> pointer to one chunk of memory is not allowed to point to a different chunk
> of memory via incrementing.
>
And, perhaps slightly more likely, to place an array beginning at
the base of a segment, so that the "-1" address does not exist.
But not to put an array exactly at the end of a segment, or the
end of the address space.  However, there need only be one byte
(perhaps otherwise unused) following the end, whereas supporting
-1 would require a whole array element (possibly quite large)
before the beginning; this asymmetry is often given as the rationale,
in addition to the asymmetry of the idiomatic half-open ranges.

...
> My point is that the C standard says you're *allowed* to implement range
> checking on arrays. In practice, very few do, and in my experience, those
> that do are specifically low-performance debugging type interpreters.
>
Yes.

--
- David.Thompson 1 now at worldnet.att.net








  reply	other threads:[~2002-06-21 17:23 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-03  9:26 Commercial C To Ada 95 compiler Henrik Quintel
2002-06-03 18:52 ` Ingo Marks
2002-06-04  6:40   ` Henrik Quintel
2002-06-04 14:11     ` Frank J. Lhota
2002-06-04 14:26       ` Preben Randhol
2002-06-04 16:38         ` Frank J. Lhota
2002-06-03 20:26 ` Florian Weimer
2002-06-04  6:43   ` Henrik Quintel
2002-06-04 14:18     ` Lutz Donnerhacke
2002-06-07  3:48 ` Richard Riehle
2002-06-07 12:46   ` SteveD
2002-06-07 13:20     ` Marin David Condic
2002-06-09 21:43       ` Stephen Leake
2002-06-10 13:17         ` Marin David Condic
2002-06-11 12:52           ` SteveD
2002-06-11 13:32             ` Marin David Condic
2002-06-12 14:07               ` Larry Kilgallen
2002-06-12 13:21                 ` Marin David Condic
2002-06-07 13:21   ` Larry Kilgallen
2002-06-07 19:48     ` Ted Dennison
2002-06-07 20:26       ` Wes Groleau
2002-06-08  3:19         ` SteveD
2002-06-08  3:59           ` Jim Rogers
2002-06-08  4:14             ` Darren New
2002-06-08  4:50               ` SteveD
2002-06-08 12:04                 ` Robert Dewar
2002-06-10 18:44               ` Wes Groleau
2002-06-10 19:23                 ` Darren New
2002-06-10 20:55                   ` Wes Groleau
2002-06-10 21:03                     ` Darren New
2002-06-08  4:46             ` SteveD
2002-06-08 12:11               ` Robert Dewar
2002-06-08 18:46                 ` SteveD
2002-06-10 13:34                   ` Marin David Condic
2002-06-11 16:38                     ` Wes Groleau
2002-06-11 17:27                       ` Marin David Condic
2002-06-12 13:18                         ` Pascal Obry
2002-06-10 18:47               ` Wes Groleau
2002-06-10 21:23                 ` Larry Kilgallen
2002-06-10 20:59                   ` Wes Groleau
2002-06-10 21:37                     ` Robert A Duff
2002-06-10 22:34                       ` Wes Groleau
2002-06-08 12:06             ` Robert Dewar
2002-06-08 15:53             ` Richard Riehle
2002-06-08 15:58               ` Preben Randhol
2002-06-10 13:37                 ` Marin David Condic
2002-06-10 23:32                   ` Darren New
2002-06-11 13:11                     ` Marin David Condic
2002-06-12 15:42                       ` Darren New
2002-06-21 17:23                         ` David Thompson [this message]
2002-06-08 17:45               ` tmoran
2002-06-08 18:32               ` Pascal Obry
2002-06-09 17:41                 ` Richard Riehle
2002-06-10  8:11                   ` Fraser Wilson
2002-06-08 20:06               ` Jim Rogers
2002-06-09 17:49                 ` Richard Riehle
replies disabled

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