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
Rich Townsend

2006-05-26, 7:04 pm

Nasser Abbasi wrote:
> "Richard Maine" <nospam@see.signature> wrote in message
> news:1hfxsjh.t88mchrssv9cN%nospam@see.signature...
>
>
>
>
> 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
>
>


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
Sponsored Links







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

Copyright 2008 codecomments.com