Re: Array Constructors



*** Hendrickson <***.hendrickson@xxxxxxx> wrote:

Are you using IMPLICIT NONE? If so, then all variables need to
be declared, even those with statement or construct level scope.

And I consider it an oddity that, for variables with statement or
construct scope, there is no way to declare the variable within its
scope. Instead, you have to declare the variable in the scoping unit.
This has the strange and confusing "side effect" that the same
declaration declares two different variables - the one with statement
scope and another one with scope of the scoping unit.

As Michael Metcalf pointed out, these are really two different
variables. They can even have some different properties. For example,
the one in the scoping unit can be an array, but an implied DO index in
an array constructor is always scalar. Yes, that means you can write
something like (I think I got this straight)

integer :: i(10),j(10)

...
write (*,*) [i,(j(i),i=1,10)]

The i index of the implied DO is scalar in spite of the declaration. The
other i, the one outside of the implied do, is an array.

By the way. Don't do that. Just because the standard allows it doesn't
mean that you have to code that way. Unless, of course, you are
submitting a candidate for a Fortran equivalent of the old annual
obfuscated C contest. :-(

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.


Quantcast