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

N.M. Maclaren nmm1@cam.ac.uk
Fri Jun 26 08:42:00 GMT 2015


On Jun 25 2015, Steve Kargl 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)

Yes, I do.  It's clear interpretation territory.  Consider the following:

   integer, parameter :: n = 4
   integer, parameter :: k(n) = [4, 8, 10, 16]
   real :: a(20)
   call fred(a(k))

So what is the type of fred's argument?  That's obvious nonsense, especially
when one comes to parameterised derived types.  Implied DO-loops aren't
expressions, but nor are they simple macro expansions, so it is unclear
whether they are allowed to have different types in different iterations.
I don't have a clue which way WG5 would jump.


Regards,
Nick Maclaren.



More information about the Fortran mailing list