Hi to everyone. I've found a problem illustrates as follows:
module mod type :: test integer :: i end type test contains subroutine equals(left, right) type(test) :: left type(test) :: right write(*,*) loc(p), loc(q) end subroutine equals end module mod program main use mod type(test), target :: tar type(test), pointer :: p=>null(), q=>null() allocate(p, q) write(*,*) loc(p), loc(q) ! First p => tar q => tar write(*,*) loc(p), loc(q) ! Second call equals(p,q) ! Third end program main
The First and Second WRITE statements work fine and loc(p) and loc(q) equal to each other in the Second part. But in the Third time, the returned WRITE statement within the SUBROUTINE outputs a wired result which loc(p) and loc(q) were no longer identical. Is there anything wrong with the code? And if so, what are the returned values in the Third WRITE statement considering that they are not the location of pointer p and q which should be equal then?