REAL, implied-do-loop, and initialization expression?
Dominique d'Humières
dominiq@lps.ens.fr
Thu Jun 25 22:06:00 GMT 2015
> Anyone see anything wrong with this code
>
> program foo
> implicit none
> integer i
> integer, parameter :: n = 4
> integer, parameter :: k(n) = [4, 8, 10, 16]
> print *, (real(1,k(i)), i=1, n)
> end program foo
>
> Shouldn't the implied-do-loop expand to
>
> print *, real(1,k(1)), real(1,k(2)), real(1,k(3)), real(1,k(4))
>
> gfortran 5 and 6 give
>
> troutmask:sgk[265] gfc6 g.f90
> g.f90:6:19:
>
> print *, (real(1,k(i)), i=1, n)
> 1
> Error: Invalid kind (0) for REAL at (1)
This remind me the problem I had when coding gfortran.dg/fmt_en.f90, hence the convoluted do loop at the beginning of the code. At that time I convince myself that, since ‘i’ is not a parameter, k(i) is not a parameter. Not sure this is right!-(
Cheers,
Dominique
More information about the Fortran
mailing list