可分配数组也可以save
具有save属性的变量,你可以理解为定义在一个特殊的空间里。
它具有永久的生命周期(指本程序的实例开始执行到进程退出),但只具有当前子程序范围内的作用域
可以思考以下子程序,尝试去掉 save 属性再试试:
[Fortran] 纯文本查看复制代码
program main
implicit none
call sub(3)
call sub(4)
contains
Subroutine sub(j)
integer :: j
integer , allocatable , save :: d(:)
if(.not.allocated(d)) then
allocate(d(j))
d = j
end if
write(*,*) d
End Subroutine sub
end program main