Re: Scope of implied-do index



Brooks Moses wrote:
"The name of a variable that appears as the DO variable of an implied-DO in a DATA statement or an array constructor has the scope of the implied-DO list. It is a scalar variable that has the type and type parameters that it would have if 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."
[...]
From this I conclude that not only is your code legal, but the following (where i is an array in the outer scope, but a scalar within the construct) is also legal:

integer i(2,0:3,5)
real x(10)
x = (/ (i, i=1, 10) /)

While I'm on the subject (and with the thought in mind that these probably ought go into the gfortran test suite), I believe that the following as well are legal:

integer, parameter :: i
real x(10)
x = (/ (i, i=1, 10) /)

integer, external :: i
real x(10)
x = (/ (i, i=1, 10) /)

integer, intrinsic :: ubound
real x(10)
x = (/ (ubound, ubound=1, 10) /)

function foo(i) result(x)
integer, intent(in) :: i
real x(10)
x = (/ (i, i=1, 10) /)
end function

And, similarly, substituting a write statement with an implied-do for the array statement in any of those should produce an error.

- Brooks


--
The "bmoses-nospam" address is valid; no unmunging needed.
.



Relevant Pages

  • Re: Scope of implied-do index
    ... in a DATA statement or an array constructor has the scope of the implied-DO list. ... It is a scalar variable that has the type and type parameters that it would have if 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." ... Aside from the fact that they're not included in the above quote, consider section 14.7.5, which includes "Beginning of execution of the action specified by an implied-DO list in an input/output statement causes the ... section 9.4.2 requires that the variable for an i/o implied-do be a scalar variable; this restriction is not there for array-constructor or data implied-do loops. ...
    (comp.lang.fortran)
  • Re: bug in g95 with character arrays?
    ... Context is irrelevant. ... Data statement values are required to be scalar anyway, ... be array constructors, regardless of whether the array constructor is ... If you are talking about character values in data statements having ...
    (comp.lang.fortran)
  • Re: I really did get burned today [LONG]
    ... > not be affected by the evaluation of any other entity within ... kind type parameter as the do-variable. ... first paragraph of section 14.1.3 where it says that the scope ... I suppose you wouldn't mind an array constructor with ac-do- ...
    (comp.lang.fortran)
  • Re: Array Constructors
    ... Scope of implied-do variables isn't the only way in which the behaviour ... If string is a character variable of length n, ... a data statement (not even if string is a structure component, ...
    (comp.lang.fortran)
  • Re: Scope of array initialization do loops
    ... Rich Townsend wrote: ... > Having left my copy of M&R at home today, can someone remind me of the ... > Does the implied do loop have its own scope? ... the array constructor, and this type shall be integer..." ...
    (comp.lang.fortran)