我正在使用参数来修复所用类型的精度。
在我尝试在接口中使用相同类型之前,这种方法工作得很好。考虑这个小例子:
module Hello
implicit none
save
integer, parameter :: K = selected_real_kind(10)
contains
subroutine dosomething(fun)
real(K) :: foo
interface
function fun(bar)
real(K) :: bar
real(K) :: fun
end function fun
end interface
end subroutine
end module
在这里,foo 将是所需的类型,而编译器(gfortran)则抱怨“bar”和“fun”。
错误是
Error: Parameter 'k' at (1) has not been declared or is a variable, which does
not reduce to a constant expression
有办法让它发挥作用吗?
(目前,我只是到处写 selected_real_kind(10) 但这一点也不优雅)
谢谢你!
最简单的方法是添加import
界面里面。模块的定义超出了接口的范围,这在某种程度上是一种错误的设计。清楚的import
将导入所有内容。
....
subroutine dosomething(fun)
real(K) :: foo
interface
function fun(bar)
import
real(K) :: bar
real(K) :: fun
end function fun
end interface
end subroutine
....
也可能:import :: K
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)