From: "Simon Harding" <[log in to unmask]>
Sent: Saturday, December 08, 2007 4:40 AM
>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.
That's right.
Think of it this way.
When you pass a named array, a descriptor of the array is passed.
If you construct an array e.g., [x,y,z], you are not passing
three descriptors - one for each of x, y, and z - instead you
are still passing ONE descriptor.
There is no guarantee that the named elements x, y, and z, are in
adjacent storage locations and in general they won't be.
So even if x, y, and z happened to be in adjacent storage
locations, a single descriptor fot the constructed array is passed.
|