我正在使用一个参数来修复使用类型的精度.这工作正常,直到我尝试在界面中使用相同的类型.考虑这个小例子:
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
Run Code Online (Sandbox Code Playgroud)
在这里,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
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个工作?(现在,我只是在处处编写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
....
Run Code Online (Sandbox Code Playgroud)
也可能: import :: K
| 归档时间: |
|
| 查看次数: |
285 次 |
| 最近记录: |