[英]Fortran segmentation fault in pointer array
我在fortran中遇到分段错误问题。 我通过调用一个子例程来分配一个指针数组,并将该数组传递给另一个子例程。
我在Linux机器上通过PGI fortran 9.0.2编译了该程序。 这是我的测试程序。 我应该如何解决这个问题?
非常感谢您的帮助。
module hogehoge
implicit none
type foo
real, pointer :: x(:)=>null()
end type foo
contains
subroutine hogehoge_func(foox)
type(foo), intent(inout) :: foox
integer i
allocate(foox%x(2048))
do i = 1, 2048
foox%x(i)=i
end do
end subroutine hogehoge_func
end module hogehoge
!main program------------------------------------------
program test
use hogehoge
implicit none
type(foo) :: foox
call hogehoge_func(foox)
print*, 'in main program'
print*, foox%x(1:20)
call hoge(foox%x)
end program test
subroutine hoge(foox)
use hogehoge
implicit none
type(foo), intent(in) :: foox
print*, 'in subroutine'
print*, foox%x(1)
end subroutine hoge
这是输出。
in main program
1.000000 2.000000 3.000000 4.000000
5.000000 6.000000 7.000000 8.000000
9.000000 10.00000 11.00000 12.00000
13.00000 14.00000 15.00000 16.00000
17.00000 18.00000 19.00000 20.00000
in subroutine
Segmentation fault
您需要从以下位置更改主程序的最后一行:
call hoge(foox%x)
至
call hoge(foox)
如果您已经定义的常规hoge
一个模块中导入的,那么编译器会拿起这种类型的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.