Re: Scope of implied-do index
- From: Rich Townsend <rhdt@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Aug 2006 23:42:57 -0400
Steven G. Kargl wrote:
ISTR reading in the F95 standard that the scope of the index
of an implied-do is limited to the implied-do. I can't locate
where I would have gotten that impression, so a pointer to
the F95 text would be much appreciated.
In particular, I interested in what the standard says about
integer i
real x(10)
do i = 1, 10
x = (/ (i, i=1, 10) /)
end do
I'm looking at the F2003 draft, but that should also apply to F95(*). In 16.3, I
read:
"The name of a data-i-do-variable in a DATA statement or an ac-do-variable in an
array constructor has a scope of its data-implied-do. It is a scalar variable
that has the type and type parameters that it would have it were the name of a
variable in the scoping unit that includes the DATA statement or array
constructor, and this type shall be integer type; it has no other attributes.
The appearance of a name as a data-i-do-variable of an implied-DO in a DATA
statement or an ac-do-variable in an array constructor is not an implicit
declaration of a variable whose scope is the scoping unit that contains the
statement."
From my reading of this, the i in the array constructor does not have any effecton the value of i in the enclosing loop. However, the i in the array constructor
gets its type because of the preceding "integer i" declaration.
If we were instead to have:
integer i
real x(10)
do i = 1, 10
x = (/ (j, j=1, 10) /)
end do
....then j now gets its type from implicit typing -- and it ends up as an
integer. Furthermore, with
integer i
real x(10)
do i = 1, 10
x = (/ (y, y=1, 10) /)
end do
....then y again gets its type from implicit typing, and ends up as a real. From
the paragraph I quote above, the ac-do-variable type must be integer type, so
this last 'program' should cause a compiler to barf. Sure enough, both my
compilers (Lahey & Intel) spit out an error.
cheers,
Rich
.
- References:
- Scope of implied-do index
- From: Steven G. Kargl
- Scope of implied-do index
- Prev by Date: Scope of implied-do index
- Next by Date: Re: Scope of implied-do index
- Previous by thread: Scope of implied-do index
- Next by thread: Re: Scope of implied-do index
- Index(es):
Relevant Pages
|