REAL, implied-do-loop, and initialization expression?

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Jun 25 22:20:00 GMT 2015


On Fri, Jun 26, 2015 at 12:06:49AM +0200, Dominique d'Humières wrote:
> > 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!-(
> 

The index of an implied-do-loop in an initialization expression is,
well, special.  I reduce the above from an example from James van
Buskirk in c.l.f.  He's also known as Mr. Initialization Expression.  :-)

implied-do-loops and gfortran have a colorful history.

-- 
Steve



More information about the Fortran mailing list