Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29352 Discussions

array bounds changing when passed to subroutine

galtay
Beginner
1,106 Views
Hello everyone, Im having some problems with my fortran 90 code and I think its a bug.

my version of the intel compiler,
ifort --version
ifort (IFORT) 11.0 20081105

The problem involves passing an array that has non-traditional bounds [ie I allocate it like allocate(arr(11:20)) ].
This seems to work fine in the same program unit, but when I pass it to a subroutine it doesnt know about the bounds and thinks the array indices go from 1-10. When I compile with no flags I just get the wrong number when I ask it to write out the elements. When I compile with -C flag for runtime error checking it tells me I'm out of bounds on the array when I ask for arr(11). I've attached code below that will compile if anyone wants to check it out. Am I doing something outside of the standard or is this a bug? Thanks

module testmod
implicit none

contains

subroutine arrbnd(order)
integer, intent(in), dimension(:) :: order
write(*,*) order(11)
end subroutine arrbnd

end module testmod

program testprg
use testmod
implicit none

integer, allocatable, dimension(:) :: order
allocate(order(11:20))
order=1
call arrbnd(order)

end program testprg


0 Kudos
4 Replies
TimP
Honored Contributor III
1,106 Views
According to your description, it's working the way the standard says it should work. As you have set your subroutine up so that the array slice starts at subscript 1, you can pass it any slice you choose.
0 Kudos
rreis
New Contributor I
1,106 Views

When you pass the array the routine will only retrieve the dimension and starting position. If you want it to know the start and end idx you could do:


subroutine arrbnd(order, istart, iend)
integer, intent(in) :: istart, iend
integer, intent(in), dimension(istart:iend) :: order
write(*,*) order(11)
end subroutine arrbnd


0 Kudos
galtay
Beginner
1,106 Views
Quoting - rreis

When you pass the array the routine will only retrieve the dimension and starting position. If you want it to know the start and end idx you could do:


subroutine arrbnd(order, istart, iend)
integer, intent(in) :: istart, iend
integer, intent(in), dimension(istart:iend) :: order
write(*,*) order(11)
end subroutine arrbnd



thanks for both replies. For some reason I though the bounds the array was allocated with were some how carried along with the array. I passed in the array bounds I wanted with istart and iend like the example above and it works just fine now. I didnt realize there was this much freedom
0 Kudos
Steven_L_Intel1
Employee
1,106 Views
The extent of the array is carried in but the standard says that for the dummy argument, the lower bound is 1 unless you say otherwise in declaring the dummy argument. This is a fequent cause of confusion. The reason is, as others have said, that you could pass an array section in so that there is no obvious meaning of lower bound.
0 Kudos
Reply