我想了解如何在 f95 中使用动态内存。
我知道 f2003 中的以下代码有效。
program main
use pippo
implicit none
integer, allocatable :: arr(:)
call createDynamic(arr)
end program main
module pippo
contains
subroutine createDynamic(arr)
implicit none
integer, allocatable,dimension(:)::arr
integer :: i,n
n=10
allocate(arr(n))
do i=1,n
arr(i) = i
end do
end subroutine createDynamic
end module pippo
Run Code Online (Sandbox Code Playgroud)
我想在 f95 中编写一个版本:正确的方法是什么?
您的代码是有效的 Fortran 95 + ISO/IEC TR-15581 对可分配数组的增强,允许可分配的虚拟参数。
在纯 Fortran 95 中,您必须在主程序中分配数组或使用指针。然而,现在是 2019 年,快到 2020 年了。没有这个 TR 几乎没有理由使用 Fortran 95。或者甚至不只是使用大多数广泛支持的 Fortran 2008 功能。
归档时间: |
|
查看次数: |
64 次 |
最近记录: |