Does Fortran 2003 implementation of deferred bound procedure requires same argument?

浪尽此生 提交于 2019-12-07 17:01:08

问题


I tried to create inside a module an abstract type

type, abstract :: AbsType
    contains
     procedure (Compute_AbsSize), deferred :: AbsSize
end type AbsType
abstract interface
    function Compute_AbsSize(this)
        import AbsType
        double precision Compute_AbsSize
        class(AbsType)::this
    end function Compute_AbsSize
end interface

type, extends(AbsType) :: ConcrType
     type(Var), dimension(4) :: Nodes ! coming from a module
    contains
     procedure :: AbsSize => ConcrTypeSize
end type ConcrType

contains

function ConcrTypeSize(this)
        double precision ConcrTypeSize
        class (ConcrType):: this        ! 
end function ConcrTypeSize

It turns out that if I write

function ConcrTypeSize(TheConcrType)
        double precision ConcrTypeSize
        class (ConcrType):: TheConcrType        ! 
end function ConcrTypeSize

the compiler (gcc) complains that TheConcrType should have the same name of the variable of the deferred function. I could not find this information, does anybody know why I have to do this, and is this correct?

Edit: I moved the last part of the quetion to this new question


回答1:


A specific binding in an extension that overrides a specific binding in the parent type must have dummy arguments that match in name and characteristics, bar the type of the passed argument, if any. This is explained in the F2008 standard in section 4.5.7.3 (similar words in F2003).

The compiler is therefore correct to complain. Remember that the name of a dummy argument can be used when the procedure is referenced, and may also be used in the PASS attribute for the binding. A mismatch in argument names doesn't make sense in those contexts.

With respect to you last paragraph it is not clear to me exactly what you want, or how that relates to the previous part of the question. However, note that components can be allocatable. Each object of type with an allocatable component could have the component allocated to a different size. Similarly, while dummy arguments in bound procedures must have matching characteristics, and a characteristic of a dummy argument is its shape, that shape could be assumed shape.



来源:https://stackoverflow.com/questions/19390401/does-fortran-2003-implementation-of-deferred-bound-procedure-requires-same-argum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!