0
在Linux環境下,我無法兩次使用pgf90 fortran編譯器調用相同的子例程。第一次調用該子程序是可以的,但第二次調用該子程序會導致分段錯誤。有人可以提出一些建議,我的代碼有什麼問題,舉例如下:Linux上pgf90編譯器第二次調用子例程的分段錯誤
P.S.與gfortran它是確定的,即使我嘗試了英特爾視覺FORTRAN,這是OK
program main
use module_Append_1DI
implicit none
integer, allocatable:: Arr(:)
integer::Brr(2)
Brr=[3, 4]
call Append_1DI(Arr,Brr)
write(*,*)Arr
call Append_1DI(Arr,Brr)
write(*,*)Arr
end program main
module module_Append_1DI
contains
subroutine Append_1DI(A,B)
implicit none
!================================================
integer, allocatable, intent(inout)::A(:)
integer, intent(in)::B(:)
integer, allocatable::temp(:)
integer::sizeA,sizeB,sizeN
!================================================
sizeA=size(A); sizeB=size(B); sizeN=sizeA+sizeB
allocate(temp(sizeN)); temp(1:sizeA)=A
call move_alloc(from=temp,to=A)
A(sizeA+1:sizeN)=B
end subroutine Append_1DI
end module module_Append_1DI
非常感謝伊恩,對於這樣的詳細回覆。我現在可以理解我的錯誤是什麼。 –