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-Attributes: gid103376,gid1094ba,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Fri, 26 May 2006 05:16:49 -0500 From: Ludovic Brenta Newsgroups: comp.lang.ada,comp.lang.fortran Subject: Re: Bounds Check Overhead 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> <44762F55.4050106@cits1.stanford.edu> Date: Fri, 26 May 2006 12:16:33 +0200 Message-ID: <87hd3d1472.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:QSy6YTR9vjGbjU5NoxOQgJWbY+c= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 62.235.56.173 X-Trace: sv3-llP+U4Tn6SGAGPe5KaIZWSzAqwd6uFdJp5h5WlBexchQR/RsjrDdWUzIIsvZUlEIhMtI92q2JtXIyOU!7mCRjdp9He2sc9svhzhX7g+BTLDQhaWW+SaOcFEjiadMDdZ8Z/5qVcF7Fy+e3UUk6iqGjI+Hrw== X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:4488 comp.lang.fortran:10284 Date: 2006-05-26T12:16:33+02:00 List-Id: Brooks Moses writes: > Simon Wright wrote: >> In Ada one should where possible use the 'Range attribute: >> for I in Some_Array'Range loop >> Process (Some_Array (I)); >> end loop; >> where I _can't_ exceeed the bounds, so it would be surprising if a >> compiler inserted bounds checks. Is there a Fortran equivalent? I seem >> to remember something like that in VAX F77, but it's been a while... > > The Fortran equivalent is: > > do i = lbound(Some_Array), ubound(Some_Array) > call Process(Some_Array(i)) > end do > > I don't know that compilers are smart enough to omit the range check, > though -- because, in the general case, it shouldn't be omitted. > There could be something in the body of the loop that modified the > loop variable -- which would be illegal code, but the whole point of > range-checking is that it works even if the code is illegal, so unless > the compiler is otherwise able to guarantee that the loop variable is > not modified by a statement in the loop, it still needs to do the > check. And that's why Ada specifies that I cannot change inside the loop, and is undefined outside the loop; see ARM 5.5 (9, 10). You seem to imply that Fortran has a similar rule, but that compilers do not enforce that rule, and therefore have to perform range checking to enforce a non-existent language rule about array access. I am confused. Could you clarify? -- Ludovic Brenta.