> -----Original Message-----
> From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of Simon Harding
> Sent: Friday, December 07, 2007 11:40
> To: [log in to unmask]
> Subject: Derived type array constructors.
>
> I have something unexpected happening. I thought it was a compiler bug but
> having picked it to pieces I wanted to check here first.
>
> The situation is as follows. I have a derived type T. I declare some scalar
> variables of that type. I pass them one by one to a routine sub1 that
> modifies them, that is fine.
>
> To simplify things at the calling end I redefined the routine to operate on
> an array of type T. My intention was to use "call sub2([x,y,z])" for example
> instead of three individual calls. However it turns out that modifications
> to the array elements x,y,z are local to sub2, and on exit the structures
> revert to their original values. On the other hand, if I work with an array
> of type T instead of discrete scalars everything does what I expect.
>
> I can supply source code if it helps.
>
> It seems as if the array constructor [x,y,z] produces an array containing
> copies of x,y,z and modifications to these do not affect the originals. Is
> that what the problem is? I have been sat here with my Fortran books for
> some time trying to find anything that refers to this, to no avail.
>
> Thanks to anyone that can help me out,
>
> Simon.
Yes, that is exactly what is happening. An array constructor is an **EXPRESSION**, not a variable. Except in
some special cases that vary by compiler, when you create any expression, the compiler creates an unnamed temporary
variable to hold intermediate results. If you pass an expression as an actual argument, this unnamed temporary is
actually passed, not the original array elements.
You will need to figure out some other method in order to get what you want.
--
Sincerely,
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423 Voice Phone: (262) 783-5869
Brookfield, WI 53008-0423 Fax Phone: (262) 783-5928
USA Mobile Phone: (414) 412-5869
E-mail: <[log in to unmask]> or <[log in to unmask]>
|