comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com (Adam Beneschan)
Subject: Re: Concerning subscript bounds checks
Date: 1996/06/28
Date: 1996-06-28T00:00:00+00:00	[thread overview]
Message-ID: <4r1hl2$4mq@krusty.irvine.com> (raw)
In-Reply-To: 4r1aep$7ga@natasha.rmii.com


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




  reply	other threads:[~1996-06-28  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   ` Adam Beneschan
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 [this message]
1996-07-01  0:00       ` Richard A. O'Keefe
1996-07-01  0:00         ` Robert A Duff
1996-07-02  0:00           ` Richard A. O'Keefe
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-25  0:00 ` William Clodius
1996-06-25  0:00 ` ++           robin
1996-06-27  0:00   ` Richard A. O'Keefe
replies disabled

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