小编use*_*498的帖子

从接口访问参数(Fortran)

我正在使用一个参数来修复使用类型的精度.这工作正常,直到我尝试在界面中使用相同的类型.考虑这个小例子:

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),但这根本不优雅)

谢谢!

fortran

4
推荐指数
1
解决办法
285
查看次数

标签 统计

fortran ×1