Fortran: Statement functions and their arguments.

toon@moene.indiv.nluug.nl toon@moene.indiv.nluug.nl
Fri Dec 31 20:54:00 GMT 1999


David,

I think the code you're testing is trying to do something illegal.
Note how, when compiled with statement functions, it tries to pass
array elements bla(istart) as offsets into arrays to an underlying
routine.

My educated guess is that this isn't possible - g77 obviously allocates
a temporary on the stack (with a copy of the indicated array element)
instead of just passing the address of bla(istart).

Compare this simple example:

      program funcy
      real a(2)
      f(x) = g(x)
      read*,a(2)
      print*,loc(a(2))
      b = f(a(2))
      print*,b
      end
      function g(x)
      real x(1)
      print*, loc(x(1))
      g = x(1) ** 2
      end

Although it works (because it uses only one array element - which is
equivalent to a scalar here), it still prints two *different* addresses
for loc(a(2)) and loc(x(1)).

I think that what the hydro program tries to do is illegal - it passes 
an array element to a statement function that has the corresponding 
argument declared as a scalar, and then subsequently hopes to have the
address of the array element passed to the underlying (actual) function.

Unfortunately, I'm not able to quote the part of the Fortran 77 Standard
that says this.

I'll take it up with comp.lang.fortran.

Hope this helps,
Toon Moene.



More information about the Gcc-bugs mailing list