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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c4cb2c432feebd9d X-Google-Thread: 1094ba,c4cb2c432feebd9d X-Google-Thread: 101deb,15c6ed4b761968e6 X-Google-Attributes: gid103376,gid1094ba,gid101deb,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!j73g2000cwa.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada,comp.lang.fortran,comp.lang.pl1 Subject: Re: Bounds Check Overhead Date: 27 May 2006 08:53:44 -0700 Organization: http://groups.google.com Message-ID: <1148745224.430464.179290@j73g2000cwa.googlegroups.com> References: <0ugu4e.4i7.ln@hunter.axlog.fr> <%P_cg.155733$eR6.26337@bgtnsc04-news.ops.worldnet.att.net> <6H9dg.10258$S7.9150@news-server.bigpond.net.au> <1hfv5wb.1x4ab1tbdzk7eN%nospam@see.signature> <4475DA61.3080001@comcast.net> <87fyivh5xh.fsf@ludovic-brenta.org> NNTP-Posting-Host: 69.170.89.0 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1148745228 5377 127.0.0.1 (27 May 2006 15:53:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 27 May 2006 15:53:48 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: j73g2000cwa.googlegroups.com; posting-host=69.170.89.0; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news2.google.com comp.lang.ada:4549 comp.lang.fortran:10360 comp.lang.pl1:1774 Date: 2006-05-27T08:53:44-07:00 List-Id: Ludovic Brenta wrote: > "robin" writes: > > "Simon Wright" writes: > >> In Ada one should where possible use the 'Range attribute: > > > > Ideally yes, but in practice, such as in sorting and averaging, > > the loop is often one or two short of the number of elements in the array. > > No problem: > > type Some_Array_Type is array (Positive range <>) of Something; > > procedure Walk (A : in Some_Array_Type) is > begin > for J in A'First .. A'Last - 1 loop > ... > end loop; > end Walk; A somewhat more general syntax is also available. Ada allows indexing of arrays using any discrete type. Discrete types include integer types and enumeration types. Enumeration types have no arithmetic operators. generic type Element_type is private; type Index_Type is (<>); type Some_Array_Type is array (Index_Type range <>) of Element; procedure Wal(A : in Some_Array_Type) is begin for J in A'First .. Some_Array_Type'Pred(A'Last) loop ... end loop; end Walk; The 'Pred attribute evaluates to the value preceding the value specified by its actual parameter. The effect is to iterate from the first index value to one before the last index value. Jim Rogers