gfortran and -fbounds-check
mimo
mimo2@free.fr
Mon Mar 19 17:25:00 GMT 2007
Tobias Burnus a écrit :
> Hi Mimo,
>
> mimo wrote:
>> Is there some way to force gfortran not to evaluate the second operand
>> of a .AND. or .OR. when the result is determined by the first argument?
> The Fortran standard does not guarantee any order. Thus the second
> argument could be evaluated before the first one on some compilers. This
> is different to C where the evaluation happens from left to right and
> stops after the final result is known.
>
> I think gfortran (and may other Fortran compilers) do the same as C but
> one should not rely on this.
>
>> I try to use -fbounds-check on a program which have some instructions
>> of the type:
>> REAL A(100)
>> DO I=1,1000
>> IF( I <= 100 .AND. A(I) > 0. ) do something
>> ENDDO
>> and this would give me an "Array reference out of bounds" when I=101
> While there will never be an out of bounds in gfortran, I think the
> error message is correct. You should use:
>
> if(I <= 100) then
> if(A(I) > 0.) do something
> end if
>
Thanks tobias for the quick answer,
Yes, you are right. That would have been the correct way to write this code.
But sometimes you inherit from thousands of lines of badly written code, and it
would still be nice to be able to debug it as extensively as possible with the
-fbounds-check option. So as gfortran uses short-circuit internally, having an
option to use this short-circuit in the bound checking also is not
unreasonnable. I'm going to file a bug.
mimo
More information about the Fortran
mailing list