我可以在 Fortran 类型中存储对过程的引用吗?
我的目标是通过将重复的参数分组为一个类型来减少 Fortran 子例程中的重复参数。但是 Fortran 不允许我对外部过程执行此操作。
这是我尝试做的一个简化示例:
module my_functions
type mytype
external :: f
end type
contains
subroutine fa()
WRITE(*,*) "yiha"
end subroutine
subroutine fb(t)
type(mytype) t
call t%f()
end subroutine
end module
program test
use my_functions
type(mytype) :: m
m%f = fa
call fb(m)
end program
Run Code Online (Sandbox Code Playgroud)
然而 gfortran 给了我
external :: f
1
Error: Unexpected attribute declaration statement at (1)
Run Code Online (Sandbox Code Playgroud) fortran ×1