带有可选参数的Fortran函数

编程入门 行业动态 更新时间:2024-10-27 16:39:54
本文介绍了带有可选参数的Fortran函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用一个运算符 .ef。,但运算符不接受可选参数。是否有可能保留我的功能,并且能够让操作员也工作?

模块核心隐含无 接口操作符(.ef。)模块过程fes 结束接口操作符(.ef。) 包含 功能fes& (& nm,wn& )& 结果(位于) 逻辑位置字符(Len = *),意图(In):: nm 字符(Len = *),意图(In),Optional :: wn End Function

Gfortran正在返回以下问题:

lib / scriptus / core.f:62:0: 函数fes& amp ; 1 错误:在(1)操作员界面的第二个参数不能是可选的

解决方案

您不允许为定义的操作提供可选参数。 Fortran 2008,Cl。 12.4.3.4.2。说:

...虚拟参数应该是非可选的虚拟数据对象...
blockquote>

这是编译器在发出错误时引用的内容:

错误: (1)处的操作员界面的第二个参数不能是可选的

注意:您可以拥有可选参数的过程,并且它们可以显示在模块中,但它们不能在带有操作符关键字的接口块中引用。你的函数 fes 看起来不错,这不是问题。你的问题是将操作符映射到函数的接口块。

I want to use an operator .ef. however the operator does not accept optional arguments. Is it possible to keep the my function and be able to have the operator working too?

Module Core Implicit None Interface Operator (.ef.) Module Procedure fes End Interface Operator (.ef.) Contains Function fes & ( & nm, wn & ) & Result (located) Logical :: located Character (Len=*), Intent (In) :: nm Character (Len=*), Intent (In), Optional :: wn End Function

Gfortran is returning the following problem

lib/scriptus/core.f:62:0: Function fes & 1 Error: Second argument of operator interface at (1) cannot be optional

解决方案

You are not allowed to have optional arguments to defined operations. Fortran 2008, Cl. 12.4.3.4.2. says:

1 ... The dummy arguments shall be nonoptional dummy data objects ...

This is what your compiler is referencing when it emitted the error:

Error: Second argument of operator interface at (1) cannot be optional

Note: you can have procedures with optional arguments and they can appear in modules, but they cannot be referenced in interface blocks with the operator keyword. Your function fes looks fine and it is not the problem. Your problem is the the interface block mapping an operator to the function.

更多推荐

带有可选参数的Fortran函数

本文发布于:2023-07-14 22:17:10,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可选   函数   参数   Fortran

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!