program xsum_nonconform
integer, parameter :: n = 3
integer :: i,ivec(n)
ivec = 1
do i=n,n
print*,ivec(1:n-1) + ivec(1:i)
end do
end program xsum_nonconform
G95, Intel Visual Fortran, and Salford don't detect a problem at
compile or run time, but gfortran -fbounds-check says
Fortran runtime error: Array bound mismatch, size mismatch for
dimension 1 of array 'ivec' (in file 'xsum_nonconform.f90', at line 6)
and Lahey/Fujitsu with -chk says something similar.
I discovered such a bug in my production code using the new Gfortran
windows binary, dated 2007-03-29 .
NAGWare Fortran 95 compiler Release 5.1(282) on Intel Linux and with
the -C=all option gives the following error at runtime:
Rank 1 of IVEC(1:I) has extent 3 instead of 2
Program terminated by fatal error
Aborted
Kind regards,
Bart
--
"Share what you know. Learn what you don't."
Yes. For the simpler but equivalent program
program xsum_nonconform_simple
integer, parameter :: n = 3
integer :: i,ivec(n)
ivec = 1
i = n
print*,ivec(1:n-1) + ivec(1:i)
end program xsum_nonconform_simple
the compilers behave the same way, but simplifying further by plugging
in n for i in the print statement to give
program xxnonconform
integer, parameter :: n = 3
integer :: ivec(n)
ivec = 1
print*,ivec(1:n-1) + ivec(1:n)
end program xxnonconform
gives a compile-time error for gfortran and g95 (the only two I
tried), with gfortran saying
xxnonconform.f90:5.7-25:
print*,ivec(1:n-1) + ivec(1:n)
1 2
Error: Shapes for operands at (1) and (2) are not conformable
NAG f95 -C=all also finds that error at run time.
-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john....@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045