Re: Array Constructors



On 28 feb, 12:05, c...@xxxxxxxxx wrote:
Hello,

Can anyone confirm that when a variable is used in an implied do loop
in an array constructor, is its value always restored afterwards. For
example, if I do:

integer :: i
integer :: XYZ(8)
call date_and_time(values = XYZ)

i = 42
write (*,"(I5)") i
write (*,"(8I5)") (/(XYZ(i),i=1,8)/)
write (*,"(I5)") i

will the last line written always be 42. Intuitively, it felt like it
should be, as I would hope that the two i's are total separate.
However, IVF complained if the variable used in the array constructor
had not been declared (with implicit none set). It does works with
IVF, but I can't see anything in the documentation that states this
must always be the case.

Chris

I can confirm this works with g95 (on Linux) too, but
I am quite surprised: I always thought implied do-loops
were very much like ordinary do loops.

Apparently, they are not.

Still, the i within the implied do-loop is a variable and
it could have been a real too, so the compiler has every
right to complain :)

Regards,

Arjen

.



Relevant Pages

  • Re: Evaluate a multidimensional array using implied Do loop
    ... do loop with a implied do loop? ...   end do ... and I've used the f2003 array constructor syntax because this is ...
    (comp.lang.fortran)
  • Re: Evaluate a multidimensional array using implied Do loop
    ... do loop with a implied do loop? ... trying for an entry in an obfuscated code contest, ... and I've used the f2003 array constructor syntax because this is ...
    (comp.lang.fortran)
  • Re: Adding new methods to existing classes
    ... It would appear the prototype registers but it's not recognizing it's own ... attributes and never iterates thru them and ultimately hits return false. ... Changing from a for..in loop to a regular for loop makes no difference. ... Use, not the Array constructor. ...
    (comp.lang.javascript)
  • Array Constructors
    ... Can anyone confirm that when a variable is used in an implied do loop ... is its value always restored afterwards. ... IVF complained if the variable used in the array constructor ... but I can't see anything in the documentation that states this ...
    (comp.lang.fortran)
  • Re: Evaluate a multidimensional array using implied Do loop
    ... do loop with a implied do loop? ... statements, and array constructors. ... more cryptic when you try to turn it into an array assignment. ... and I've used the f2003 array constructor syntax because this is ...
    (comp.lang.fortran)