For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2006 > Re: Bounds Check Overhead









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Bounds Check Overhead
Nasser Abbasi

2006-05-26, 7:04 pm


"Richard Maine" <nospam@see.signature> wrote in message
news:1hfxsjh.t88mchrssv9cN%nospam@see.signature...
> Ludovic Brenta <ludovic@ludovic-brenta.org> wrote:
>
> [that an loop index shall not change within a loop]
>


> Others have replied some, but let me make my attempt at clarification
> because yes, you seem to be 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;

<about loop counters being changed.>

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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com