comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Concerning subscript bounds checks
Date: 1996/07/01
Date: 1996-07-01T00:00:00+00:00	[thread overview]
Message-ID: <Dtv6A6.B5K@world.std.com> (raw)
In-Reply-To: 4r7r65$nj@goanna.cs.rmit.EDU.AU


In article <4r7r65$nj@goanna.cs.rmit.EDU.AU>,
Richard A. O'Keefe <ok@goanna.cs.rmit.EDU.AU> wrote:
>	type Coord is (X,Y,Z);
>	type Point is array (Coord) of Float;
>So Simplex_Range has to be some other type.  The obvious thing was
>	subtype Simplex_Range is Natural range 0 .. Point'Length;
>(note that not only is the first value of I in this case not zero,
>it isn't even a number).  The next obvious thing is
>
>	for I in Point'Range loop
>	    let J be Simplex_Range'Val(
>		Point'Range'Pos(I) - Point'Range'Pos(Point'Range'First))
>	    P(J) := ...
>	
>However, I couldn't figure out any way to code that conversion from I to J.
>(The immediate problem is that Point'Range is a _range_, not a _(sub)type_,
>so Point'Range'Pos is inexpressible.)

What's wrong with "Coord'Pos(I) - Coord'Pos(Point'First)"?

By the way, if you have an array with unknown bounds, you can construct
a subtype for those bounds like this:

    subtype The_Range is The_Index_Type range The_Array'Range;

But there's no need to do that to use the 'Pos attribute.

Note that for T'Pos, the bounds of subtype T are ignored -- all that
matters is the type of that subtype.  For example:

    subtype S is Character range 'a'..'b';
    X: Integer := S'Pos('*'); -- No problem here.

S'Pos('*') is exactly the same as Character'Pos('*').

- Bob




  reply	other threads:[~1996-07-01  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-21  0:00 Concerning subscript bounds checks Richard A. O'Keefe
1996-06-21  0:00 ` Robert Dewar
1996-06-24  0:00   ` William Clodius
1996-06-27  0:00     ` Richard A. O'Keefe
1996-06-28  0:00       ` Ken Thomas
1996-06-24  0:00   ` Richard A. O'Keefe
1996-06-24  0:00     ` Robert Dewar
1996-06-28  0:00     ` joeuser
1996-06-28  0:00       ` Adam Beneschan
1996-07-01  0:00       ` Richard A. O'Keefe
1996-07-01  0:00         ` Robert A Duff [this message]
1996-07-02  0:00           ` Richard A. O'Keefe
1996-06-24  0:00   ` Adam Beneschan
1996-06-25  0:00 ` ++           robin
1996-06-27  0:00   ` Richard A. O'Keefe
1996-06-25  0:00 ` William Clodius
replies disabled

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