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,start X-Google-Attributes: gidf891f,public X-Google-Thread: 103376,eac70c5fad02d925,start X-Google-Attributes: gid103376,public From: ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe) Subject: Concerning subscript bounds checks Date: 1996/06/21 Message-ID: <4qdj3e$btf@goanna.cs.rmit.EDU.AU>#1/1 X-Deja-AN: 161344676 summary: Good one, Ada! organization: Comp Sci, RMIT, Melbourne, Australia keywords: subscripts newsgroups: comp.lang.ada,comp.lang.misc nntp-posting-user: ok Date: 1996-06-21T00:00:00+00:00 List-Id: 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.