[Fortran] 纯文本查看 复制代码 module mod_parasetting
integer,public::a
contains
subroutine parasetting()
implicit none
integer b
a=3
b=1
return
end subroutine parasetting
end module mod_parasetting
module mod_sum
contains
subroutine summarization(s)
use mod_parasetting,only:a
implicit none
integer s(a),d
integer,external::summ
d=2
s=summ(d)
return
end subroutine summarization
end module mod_sum
function summ(d) result(r)
use mod_parasetting,only:a
implicit none
integer d,c(a)
integer r(a)
integer i
c=1
do i=1,a
r(i)=c(i)+d
enddo
return
end function summ
program main
use mod_parasetting
use mod_sum
implicit none
integer,allocatable::s(:)
call parasetting()
allocate(s(a))
call summarization(s)
write(*,*) s
end program main
如上述代码,我在mod_summ模块里定义了一个子函数summ,要输出的形参时r,是一个数组,为什么我在调试的时候,到计算r这一步会中断,然后显示:
forrtl: severe (157): Program Exception - access violation
我看到r这个数组是undefined address
为啥会这样呢,求助各位大佬!!感谢!!
|