[Patch, fortran-dev] ALLOCATE statements with CLASS variables

Paul Richard Thomas paul.richard.thomas@gmail.com
Wed Sep 23 18:56:00 GMT 2009


Dear Janus,


> 1) "ALLOCATE (x, SOURCE=y)" does not work correctly if y is a CLASS.
> In this case the the size of the allocated block must be determined at
> runtime (and is then basically the size of y, which is: the size of
> the dynamic type of y). I have not managed to put this correctly into
> gfc_trans_allocate yet. If anyone known how to do this, let me know.

One slightly evil and very kludgy temporary fix would be to enclose it
in a SELECT TYPE (y)....?

>
> 2) There is another subtlety for "ALLOCATE (x, SOURCE=y)", already
> when y is just a TYPE variable (not CLASS). When initializing x, we
> basically need to do
>
> *x.$data = y   ! (this is a real structure copy, not just a pointer assignment)
>
> But x.$data is, say, TYPE(t1), and y may be some other TYPE(t2), which
> can be any descendant of t1. Now one must no only initialize the
> components which are already present in t1, but also those that have
> been added in t2. Therefore some type-casting is needed. One may do
> this either via a temporary, or maybe just some memcpy?!?

I do this in the patch to trans-expr.c for the actual/formal ==
derived/class fix.

Cheers

Paul



More information about the Fortran mailing list