(j3.2006) SAVE and MAXLOC - Fortran 95 <-> 2003 incompatibility?

Tobias Burnus burnus
Thu Sep 20 04:50:29 EDT 2012


Hi all,

I have a question: Does the variable "x" have the SAVE attribute or not 
in the following program. (Or ask reversely, is "x" an automatic 
variable or not?)

Depending on the compiler, I get the result "1" or "2". In Fortran 95, 
MINVAL is not an initialization expression, in Fortran 2003/2008 it is.

And all standards state (e.g. F2008, 5.4.14 SAVE statement, para. 1, 
page 108):

"[...] A SAVE statement without a saved entity list is treated as though 
it contained the names of all allowed items in the same scoping unit."

Is this just an incompatibility between Fortran 95 and Fortran 
2003/2008? Or have I missed something, e.g. an interpretation request.

(The program was posted by James Van Buskirk in comp.lang.fortran.)

module m4procs
    implicit none
    contains
       recursive function fun(depth) result(r)
          integer r
          integer depth
          integer x(minval((/1/)))
          integer y
          save

          x = 0
          if(depth > 0) y = fun(depth-1)
          x = x+1
          r = x(1)
       end function fun
end module m4procs

program minval4
    use m4procs
    implicit none

    write(*,*) fun(1)
end program minval4




More information about the J3 mailing list