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!newsfeed.stanford.edu!shelby.stanford.edu!not-for-mail From: Brooks Moses Newsgroups: comp.lang.ada,comp.lang.fortran Subject: Re: Bounds Check Overhead Date: Thu, 25 May 2006 15:27:33 -0700 Organization: Stanford University Message-ID: <44762F55.4050106@cits1.stanford.edu> 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> NNTP-Posting-Host: dnab42a45b.stanford.edu Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.Stanford.EDU 1148596059 14708 171.66.164.91 (25 May 2006 22:27:39 GMT) X-Complaints-To: news@news.stanford.edu User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en In-Reply-To: Xref: g2news2.google.com comp.lang.ada:4476 comp.lang.fortran:10260 Date: 2006-05-25T15:27:33-07:00 List-Id: 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. - Brooks -- The "bmoses-nospam" address is valid; no unmunging needed.