【发布时间】:2018-06-20 23:56:29
【问题描述】:
我可以在 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
然而 gfortran 给了我
external :: f
1
Error: Unexpected attribute declaration statement at (1)
【问题讨论】:
-
具体来说,我有一个对象,它依赖于几个用户提供的外部函数,我不想在每次调用该对象的方法时都传递所有这些函数。
标签: fortran