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!news3.google.com!news.glorb.com!news.aset.psu.edu!news.cse.psu.edu!elk.ncren.net!scrotar.nss.udel.edu!not-for-mail From: Rich Townsend Newsgroups: comp.lang.ada,comp.lang.fortran Subject: Re: Bounds Check Overhead Date: Fri, 26 May 2006 14:26:04 -0400 Organization: University of Delaware Message-ID: 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> <87hd3d1472.fsf@ludovic-brenta.org> <1hfxsjh.t88mchrssv9cN%nospam@see.signature> NNTP-Posting-Host: shayol.bartol.udel.edu Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: scrotar.nss.udel.edu 1148667955 2071 128.175.14.63 (26 May 2006 18:25:55 GMT) X-Complaints-To: abuse@udel.edu NNTP-Posting-Date: Fri, 26 May 2006 18:25:55 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0.8 (X11/20060417) X-Accept-Language: en-us, en In-Reply-To: Xref: g2news2.google.com comp.lang.ada:4504 comp.lang.fortran:10303 Date: 2006-05-26T14:26:04-04:00 List-Id: Nasser Abbasi wrote: > "Richard Maine" wrote in message > news:1hfxsjh.t88mchrssv9cN%nospam@see.signature... > >>Ludovic Brenta wrote: >> >> >>>You seem to imply that Fortran has a similar rule, >> >> [that an loop index shall not change within a loop] >> >>>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? >> > >>Others have replied some, but let me make my attempt at clarification >>because yes, you seem to be confused about multiple related things here. >> >>Yes, there is a Fortran language rule that a loop index shall not be >>changed while a loop is executing. Compilers are not required to enforce >>that rule, but essentially all compilers make at least some attempt to >>enforce it and catch the simple cases, which is most cases, but not all. >>There are cases where the violation of the rule is hard to detect, >>because the change occurs in some other procedure. >> > > > Hello; > > > > I am not sure if there is supposed to compiler flag to enforce this or not, > you do not seem to imply that, so I did this very simple test, please see: > > ------------ test for checking on changing loop index---- > $ cat a.f90 > > PROGRAM MAIN > > DO I=1,10 > CALL foo(I) > PRINT *,I > END DO > > END PROGRAM > > SUBROUTINE foo(I) > I=I+1 > END SUBROUTINE > ------------- end program ------ > $ g95 a.f90 > $ ./a.exe > 2 > 4 > 6 > 8 > 10 > 12 > 14 > 16 > 18 > 20 > --------- end run --------- > > I did the same in Ada: > > --------- Ada ------- > procedure Main is > > PROCEDURE foo(I: in out integer) IS > begin > I:=I+1; > end foo; > > BEGIN > > FOR I IN 1..10 LOOP > foo(I); > END LOOP; > > END Main; > ------- end ada ---- > > The above will not even be allowed to compile since Ada wants 'I' to be an > actual variable. > > The compile error I get is "actual for I must be a variable" > > This means I am not even allowed to use "I" in a call. > This eliminate the problem from accidentally change the loop counter. > > Nasser > > I don't think you're comparing like-for-like. A better comparison: PROGRAM MAIN DO I=1,10 CALL foo(I) PRINT *,I END DO CONTAINS SUBROUTINE foo(I) INTENT(in) :: i I=I+1 END SUBROUTINE END PROGRAM MAIN Also, from looking at your Ada program, it seems you can't pass loop counters to procedures. Is this the case? cheers, Rich