[RFC] polymorphic arrays
Janus Weil
janus@gcc.gnu.org
Fri Aug 6 11:29:00 GMT 2010
Hi Thomas,
>> 1) Use the class container also for polymorphic arrays, and have the
>> "$data" field point to an array descriptor.
>
> I have to confess my ignorance here, but...
>
> Can different array elements have different types? If so, this method
> probably would not work.
no, IIUC all array elements must have the same dynamic type. (Btw your
comment applies in the same way to the second option I proposed.)
To be honest, I have not found any direct statement on this in the
standard. But I would not know how to set up an array which has
different dynamic types, because:
1) Class arrays must have either the POINTER or ALLOCATABLE attribute
(or be dummy arguments, where the actual argument passed would be
either POINTER or ALLOCATABLE).
2) An array with POINTER attribute in Fortran is not an array of
pointers, but a single pointer to an array. If you use such a
polymorphic pointer to point to an actual array, all elements would
have the same type.
3) For an allocatable array, the ALLOCATE statement will always create
an an array with all the same types. And I don't see any way to change
the type of single elements.
Hope I'm not missing anything.
Cheers,
Janus
More information about the Fortran
mailing list