Re: Array Constructors
- From: Klaus Wacker <wacker@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 16:55:19 +0000 (UTC)
*** Hendrickson <***.hendrickson@xxxxxxx> wrote:
cjk32@xxxxxxxxx wrote:
On 28 Feb, 12:50, "Michael Metcalf" <michaelmetc...@xxxxxxxxxxxxxx>
wrote:
<c...@xxxxxxxxx> wrote in message
news:1172660739.879054.15000@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,Please note that the do variable of an implied-do in a DATA statement or an
Can anyone confirm that when a variable is used in an implied do loop
in an array constructor, is its value always restored afterwards.
array constructor has a scope that is just the implied-do. It is different
from any other entity with the same name (i.e., you have two variables
called i in your snippet, so to think about 'restoring' is not correct).
(See also MR&C, Section 5.15.)
That was my initial thought, but IVF complaining if *a* variable, i,
wasn't declared somewhere in the same scope in unsettled me somewhat.
Arjen makes a good point, but if I try it with a non integer variable,
IVF complains again, saying that an integer is required. I guess this
is just a bug in the IVF compiler.
Are you using IMPLICIT NONE? If so, then all variables need to
be declared, even those with statement or construct level scope.
The OP said he was using IMPLICIT NONE. I think we had this discussion
here recently. If I remember correctly: Yes, with IMPLICIT NONE you
need a type declaration for the variable with the constructor scope.
Since there is no way to put that declaration inside the scope, you
have to put it outside, at the top of the subroutine or function or
whatever. When you have a variable of the same name outside of the
constructor, the declaration applies automatically also to this
variable. So, with one declaration you declare the properties of two
things. This a somewhat confusing consequence of the fact that you
have a limited scope with no possibility to put a declaration inside.
And the outside variable cannot have a type different from the one
inside, and that type better be integer. This is also the case without
IMPLICIT NONE and without explicit type declarations.
--
Klaus Wacker klaus.wacker@xxxxxxx
Experimentelle Physik V http://www.physik.uni-dortmund.de/~wacker
Universitaet Dortmund Tel.: +49 231 755 3587
D-44221 Dortmund Fax: +49 231 755 4547
.
- References:
- Array Constructors
- From: cjk32
- Re: Array Constructors
- From: Michael Metcalf
- Re: Array Constructors
- From: cjk32
- Re: Array Constructors
- From: *** Hendrickson
- Array Constructors
- Prev by Date: Re: Array Constructors
- Next by Date: Re: Array Constructors
- Previous by thread: Re: Array Constructors
- Next by thread: Re: Array Constructors
- Index(es):