Question

Am working with some legacy FORTRAN code. The author defined a function (not a subroutine, but a function -- that's going to be important) called REDUCE_VEC(). It accepts a 1D array and returns a scalar real*8. So, if you want to "reduce" your vector, you make a call to the function

RV = REDUCE_VEC(V1)

and everything is fine. But occasionally, he has lines that look like

CALL REDUCE_VEC(V2)

So, two questions: 1) What the heck would this second form of the call do? (Note that there is no way to return data.) 2) This won't even compile under gfortran, even though it did with PGI, so is this even legal FORTRAN?

Thanks.

Was it helpful?

Solution 2

It is not legal Fortran. As presented it is more than likely a programming error (it is possible for the same name in different scopes to refer to different things, but that's not what is implied by the question). If the Fortran processor happens to support an extension to the language that allows this, then what happens is up to the Fortran processor. Otherwise, "anything" could happen, where "anything" could include (but is not limited to) "nothing", or "very, very bad things".

OTHER TIPS

This will compile with many processors if the interface is implicit, because the compiler cannot check that, it just calls some symbol. Consider the following:

function f(a)
  dimension a(*)
  f = 0
  do i=1,10
    f = f + a(i)
  end do
end function

program p
  call f([1.,2.,3.,4.,5.,6.,7.,8.,9.,10.])
end program

Compiles and does not even crash immediately with ifort, whereas sunf90 and gfortran will compile that only if it is in separate source files and then the result also does not crash on my machine. If the return value is placed in register, it may cause no harm to the rest of the program, but a stack corruption is quite likely otherwise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top