问题
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