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: f891f,eac70c5fad02d925 X-Google-Attributes: gidf891f,public X-Google-Thread: 103376,eac70c5fad02d925 X-Google-Attributes: gid103376,public From: adam@irvine.com (Adam Beneschan) Subject: Re: Concerning subscript bounds checks Date: 1996/06/28 Message-ID: <4r1hl2$4mq@krusty.irvine.com>#1/1 X-Deja-AN: 163123701 references: <4ql9eq$hdt@goanna.cs.rmit.EDU.AU> <4r1aep$7ga@natasha.rmii.com> organization: /z/news/newsctl/organization keywords: subscripts newsgroups: comp.lang.ada,comp.lang.misc Date: 1996-06-28T00:00:00+00:00 List-Id: joeuser@satcom.whit.org (joeuser) writes: >I think I have the right piece of text here. > > > >The remaining 4 occur in this context: > > subtype Simplex_Range is Natural range 0 .. Point'Length; > > P: "array (Simplex_Range) of ..." > > Y: "array (Simplex_Range) of ..." > > X: Point; > > J: Simplex_Range; > > ... > > J := 0; -- at the start, J = Simplex_Range'First > > for I in X'Range loop > > ... > > P(J) := ... > > Y(J) := ... > > J := J + 1; > > end loop; -- at the end, J = Simplex_Range'Last > > P(J) := ... > > Y(J) := ... > >end; > > >A reasonably smart compiler should be able to tell that these four > >subscripts are also safe. > > >and this is intuitively obvious to the most casual observer? > >I think not. > >Your problem lies in the J:=J+1; statement > >You would be better off to use I as your index and not J. (and it would work >too.) Here is why. > >What happens the first time through this loop? > >I=0 >J=0 Uh, no. The definition of "Point" isn't shown here, so how can you assume that Point'first = 0? Just from looking at the above code, without seeing the definition of Point, my guess is that Point is an array whose 'first is 1, and the intent was deliberately to make P and Y arrays with one more element than X. >BUT guess what!!!! >J:=J+1; > >That means that when I=X'Last >J will become X'Last+1 > >This basically equates to Simplex_Range'Last+1 > Hence-----> your constraint error *Whose* constraint error? Nobody ever posted this code fragment complaining about a constraint error or about code that doesn't work. The issue being discussed was whether the unnecessary constraint checks could be eliminated by a smart compiler. -- Adam