From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,eac70c5fad02d925 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Concerning subscript bounds checks Date: 1996/07/01 Message-ID: #1/1 X-Deja-AN: 163084332 references: <4qdj3e$btf@goanna.cs.rmit.EDU.AU> <4ql9eq$hdt@goanna.cs.rmit.EDU.AU> <4r1aep$7ga@natasha.rmii.com> <4r7r65$nj@goanna.cs.rmit.EDU.AU> organization: The World Public Access UNIX, Brookline, MA keywords: subscripts newsgroups: comp.lang.ada Date: 1996-07-01T00:00:00+00:00 List-Id: In article <4r7r65$nj@goanna.cs.rmit.EDU.AU>, Richard A. O'Keefe 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