mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Mon Feb 02, 2015 1:48 am Post subject: Compiler gives false bounds error with /check |
|
|
In the following program, a section of an assumed shape 2-D array is passed to a function which expects a 1-D array. The 7.10 FTN95 compiler gives a false bounds error as indicated in the listing. Viewing the run in SDBG shows the array X as having a dimension (1) at the point where the program aborted.
The program should run without error.
Code: | ! Compile with /check and run
! Will give false "array subscript out of bounds"
! error in function SNRM2 below
program arraybug
implicit none
real, dimension(:,:), allocatable :: c
integer m,n,i,j
real :: x
m=3
n=4
allocate(c(m,n))
do i=1,m
do j=1,n
c(i,j)=100*i+j
end do
end do
call sub(c,m)
contains
subroutine sub(c,m)
implicit none
integer :: m
real, dimension(:,:) :: c
x=snrm2(m,c(:,2))
write(*,*)x
end subroutine
function snrm2(n,x) result(ssq)
implicit none
real :: x(*),ssq,absxi
integer :: n,i
ssq=0
do i = 1, n
absxi = abs ( x(i) ) ! <<<=== falsely gives subscript error here!
ssq = ssq + absxi**2
end do
return
end function snrm2
end program
|
[P.S., 15 June 2015: The fix described by Paul Laidler is present in FTN95-7.20]
Last edited by mecej4 on Mon Jun 15, 2015 11:46 pm; edited 1 time in total |
|