问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/30080094/fortran-functions-with-optional-arguments