Polymorphism allocation in a SELECT TYPE construct

和自甴很熟 提交于 2019-12-11 03:02:50

问题


I am trying to define a subroutine which allocates different types of arrays. Here is a simplified version of the code:

subroutine Allocation1(Vec)
    class(*), allocatable, intent(out)      :: Vec(:)

    select type(Vec)
    type is(real(8))
        allocate(Vec(10)); Vec = 0.D0
    type is(complex(8))
        allocate(Vec(10)); Vec = (0.D0,0.D0)
    type is(integer)
        allocate(Vec(10)); Vec = 0
    endselect
endsubroutine Allocation1

But I got three error messages that I don't understand:

error #8306: Associate name defined in ASSOCIATE or SELECT TYPE statements doesn't have ALLOCATABLE or POINTER attribute   [VEC]

As you can see VEC is an allocatable array, so I don't think this error make sense. What does it mean, and how do I make this work?

I am using IVF XE 14.0.1.139.


回答1:


Seems like a compiler bug, works with Gfortran and with the Solaris Studio. I recommend you to contact your official Intel support.

As IanH points out, it is possible the other compilers are in error to compile that. Anyway, be it standard conforming or not, the procedure would still be useless, because for the select type to work the variable would still have to be already allocated, because the actual argument to your procedure must be polymorphic. You cannot just pass real, allocatable there.




回答2:


A variable with intent(out) attribute is not allocated, so Vec will have no type and SELECT TYPE(VEC) is undefinable.



来源:https://stackoverflow.com/questions/26284342/polymorphism-allocation-in-a-select-type-construct

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