Re: parametrized derived types vs. allocatable components
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Mon, 30 Nov 2009 09:52:09 -0800
m <mrestelli@xxxxxxxxx> wrote:
Hi,[code using allocatable components elided]
I need to define an array of elements of derived type having in
turn an array component. The size of the array component is given at
run-time, but I know that it will be the same for all the elements of
the array. A possible solution would be:
I wonder whether one could use parametrized derived type as follows:[mostly elided, except for relevant lines]
type(tbvec(:)), allocatable :: bvec....
The syntax on allocate is wrong there. That's the syntax for allocating
an array, which isn't (directly) what you are doing. Your bvec is a
scalar, even though it has array components. You want the form for
specifying a type and type parameters during allocate, which would be
Is xyz_pdt correct (I don't have any compiler to test it :-( )?
See above correction, but I don't have a suitable compiler either.
Would xyz_pdt allow a reference of the form:
No. At least I doubt it. Someone else can check the citation if they
want, but this looks like something that "shouldn't" work. I think the
prohibitions are written generally enough to catch it. Probably
something about a designator not allowing allocatable or pointer things
to the right of a part with nonzero rank.
Does anybody see any advantage in one of the two forms (concerning for
instance efficiency or flexibility)?
Well, a big advantage of the allocatable components form is that most of
today's compilers support it. Parameterized derived types seem to be
pretty much the last f2003 feature to get implemented. I don't recall
that a single compiler has them yet. Implementation has lagged so much
that the question has at least been raised of whether to pull them from
the language. (That doesn't seem likely to happen, from what I read
here, but I no longer have a very good insight into some of the
committee ongoings; all my data is second hand and I'm not at all sure
that all I read is impartially reported).
A more nebulous advantage of allocatable components is that they seem to
me to be easier to read. I base that solely on looking at your example
codes; it isn't a comparison I had particularly thought to make before.
I just note that I seemed to have to reread your PDT example multiple
times to get it all straight. Perhaps it is just that I'm more used to
the allocatable components stuff. Or maybe I'm just not focussing well
at the moment and would find it different tomorrow. Who's to say? Take
this comment for whatever it might be worth.
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
- Prev by Date: parametrized derived types vs. allocatable components
- Previous by thread: parametrized derived types vs. allocatable components