Re: Derived types with allocatable arrays; more problems



Thanks for your swift reply.

If you explicitly write
do i = 1, n
a%b(i) = b(i)
end do
it works.

If b(i)%c=c (=integer array) works fine, why shouldn't a%b=b (=derived
type array) work in the same way?

Also it seems that you allocated a%b(n) but you did not allocate
a%b(i)%c(n)

If a derived type (b(i) in this case) contains an allocatable array, it
will automatically become allocated in an assignment, as far as I
understood. So, if I understood correctly, I do not need to explicitly
allocate a%b(i)%c(n).

I think that the problem is in the assignment between two derived
types. You'd better define your own assignment operator (=).

I used to have that when I was still using pointers, but now I switched
to allocatable arrays in derived types and thought/hoped I could live
without my own assignment operators.

I just don't understand why the code doesn't work, and before altering
(large chunks of) code, I would like to know what is going on. I will
keep in mind the extra loop you suggested.

Arno

.



Relevant Pages

  • Re: getting offset of allocatable derived types
    ... type that has an allocatable array as one of its components. ... derived type contains an allocatable. ... The function is to get the offset in memory ...
    (comp.lang.fortran)
  • Re: Parsing parameters of User Defined types
    ... or find documented examples of how to initialize an array ... of a derived type. ... it is still a continuous string subject to line continuation limits. ...
    (comp.lang.fortran)
  • Re: Parsing parameters of User Defined types
    ... or find documented examples of how to initialize an array ... I figured out the initializing of an array of a derived type and yet ... which avoids line length limitations when combined w/ allowable continuation line limits, ...
    (comp.lang.fortran)
  • Re: overload array index operator
    ... >> Is there any way to overload the index operator in fortran? ... >> example if I want to index an array with a derived type? ... > to write portable code based on these standards. ...
    (comp.lang.fortran)
  • Re: Unions in Fortran
    ... 1) in an array, b) as a derived type, like ... Using a derived type is much more readable, ... One can, however, declare constants ... derived type (IMO), but with the added convenience of an array. ...
    (comp.lang.fortran)