comp.lang.ada
 help / color / mirror / Atom feed
* Concerning subscript bounds checks
@ 1996-06-21  0:00 Richard A. O'Keefe
  1996-06-21  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Richard A. O'Keefe @ 1996-06-21  0:00 UTC (permalink / 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.




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~1996-07-02  0:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` 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
1996-07-02  0:00           ` Richard A. O'Keefe
1996-06-25  0:00 ` ++           robin
1996-06-27  0:00   ` Richard A. O'Keefe
1996-06-25  0:00 ` William Clodius

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