I'm new in the field of pointers and I wonder a little bit on one thing. Here is my example:
program main_program interface subroutine sub_ptr(b) real, dimension (:), pointer :: b end subroutine sub_ptr end interface ! real, dimension (:), pointer :: a ! call sub_ptr(a) write(*,'(<size(a)>f6.2)') a end program main_program
subroutine sub_ptr(b) real, dimension (:), pointer :: b real, dimension (:), allocatable, target :: c integer, parameter :: m = 5 integer :: i allocate (b(m)) allocate (c(m)) do i = 1, m c(i) = float(i) end do b = c ! this is how it works !b => c ! this is how it not works continue end subroutine sub_ptr
If I assign b to c by => in the subroutine, the result of a in the main program is garbage. Doing the same just with the equal sign, a contains the expected data...
Is this caused by the fact, that all variables of the subroutine are freed, if the subroutine is finished? Then the pointer points into nirvana?
Best regards, Johannes
ps: In ifort XE 188.8.131.529 and VS 2010 SP1 the array c is not correctly shown in debug mode, when hovering the mouse on it: "Undefined pointer/ array" Also in watch window. Is this a bug?