4
有人可以解釋爲什麼下面的程序不工作,以及如何使它工作? 在主程序中我分配一個指針,在子程序sub
中查找數組的形狀並得到錯誤的值。陣列和指針形狀
program test
real, pointer, dimension(:,:,:) :: arr
allocate(arr(3,5,7))
print *, "In test: ",shape(arr)
call sub(arr)
print *, "Back in test: ",shape(arr)
end program test
subroutine sub(arr)
real, pointer, dimension(:,:,:) :: arr
print *, "In sub: ",shape(arr)
end subroutine
輸出:
In test: 3 5 7
In sub: 12694064 1 3
Back in test: 3 5 7
感謝
PS:我使用gfortran(GCC 4.4.3)
編輯:與gfortran 4.6,該代碼根本不編譯。我得到的錯誤:
Dummy argument 'arr' of procedure 'sub' at (1) has an attribute that requires an explicit interface for this procedure