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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Bounds Check Overhead Newsgroups: comp.lang.ada,comp.lang.fortran,comp.lang.pl1 User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH 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> Date: Sat, 27 May 2006 17:59:42 +0200 Message-ID: <1q4rxn8ktn7dt.1wjrxfwrlt6yk.dlg@40tude.net> NNTP-Posting-Date: 27 May 2006 17:59:42 MEST NNTP-Posting-Host: 08c9c356.newsread2.arcor-online.net X-Trace: DXC=DM=cbGG_^eZD__2dTlB=E[Q5U85hF6f;TjW\KbG]kaMXVA=iV<7g:2U8k=I=NSeHh[WRXZ37ga[7ZjTA67ckJ=XU`ekcfE7=N0Z X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4550 comp.lang.fortran:10361 comp.lang.pl1:1775 Date: 2006-05-27T17:59:42+02:00 List-Id: On Sat, 27 May 2006 16:56:58 +0200, 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; I don't think it is same. A range expression of A'First and A'Last is not statically required to be a subrange of A'Range (or maybe empty). So the compiler had to prove that, if it would wish to omit checks. In your example it is trivially provable (if nobody had played with "-"), though I am not sure if, say, GNAT really does it. Somebody had mentioned OCaml, I really doubt that inference is the answer. The programmer knows far more than the compiler (or pier viewer) could infer. If J has to be in A'Range, I prefer that it could be specified rather than deduced. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de