From: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe)
Subject: Concerning subscript bounds checks
Date: 1996/06/21
Date: 1996-06-21T00:00:00+00:00 [thread overview]
Message-ID: <4qdj3e$btf@goanna.cs.rmit.EDU.AU> (raw)
There was some discussion in comp.lang.misc recently about array bounds
checks. As an exercise, I converted Algorithm AS 47 (an implementation
of the Nelder-Mead simplex minimisation procedure) from Fortran to Ada.
The Fortran original contains 85 array subscripts.
The Ada version contains 66 array subscripts.
Of these 66, all but 4 occur within the scope of a "for" loop
which *obviously* guarantees the safety of the subscript.
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.
--
Fifty years of programming language research, and we end up with C++ ???
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.
next reply other threads:[~1996-06-21 0:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-06-21 0:00 Richard A. O'Keefe [this message]
1996-06-21 0:00 ` Concerning subscript bounds checks Robert Dewar
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
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-24 0:00 ` Adam Beneschan
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