Hello, I am having trouble with calling a procedure via pointer. I am not sure if this is my misunderstanding of the fortran standard, or a compiler problem. In the piece of code shown below, a call to a procedure pointer does not produce the expected results. Arrays 'n1' and 'n2', previously allocated with a certain size ('hmuch') when passed to a pointer 'proc', give an 'ubound' value of 0. If passed to 'a_1' , or 'a_2' directly (so, 'call a_1(n1,n2)' instead of call 'proc(n1,n2)'), ubound returns the correct sizes of the arrays.
The way I see it this is one of the following: 1) My code is correct, this is a compiler bug 2) My code has an intricate error, but compiler compiles blissfully, instead of signaling a dangerous omission which has apparently something to do with the interface information available in the main program. 3) This is a daft error on my side, the one i wouldn't make have I stopped coding hours ago and resumed after recharging my mana. Can somebody help me figure out what is actually going wrong?
The version of the compiler is: ifort (IFORT) 11.1 20091012
THE CODE FOLLOWS:
module procs implicit none contains subroutine a_1(x,y) complex,dimension(:),intent(in) :: x,y !I should be able to pass allocatable arrays to this subroutine, right? print *, 'x', ubound(x) print *, 'y', ubound(y) end subroutine a_1 subroutine a_2(x,y) complex,dimension(:),intent(in) :: x,y print *, 'xx', ubound(x) print *, 'yy', ubound(y) end subroutine a_2 end module procs program bullgrog use procs implicit none procedure(), pointer :: proc !the procedure pointer used further below to call a_1 or a_2, depending on the value of 'sel' integer :: sel,hmuch complex,dimension(:),allocatable :: n1,n2 hmuch=30 sel=1 if (sel .eq. 1) then proc => a_1 !so 'proc' will point to 'a_1' else proc => a_2 end if allocate(n1(hmuch)) allocate(n2(hmuch)) print *, 'n1', ubound(n1) !30 print *, 'n2', ubound(n2) !30 call proc(n1,n2) !THE PROBLEM --> I would have thought the result is 'x 30 n y 30', but, no, it is 'x 0 n y 0' !! Huh?? call a_2(n1,n2) ! a direct call returns 'xx 30 n yy 30' like i thought end program bullgrog