[comp.lang.fortran] Question about variables local to s

hirchert@uxe.cso.uiuc.edu (08/24/89)

Rostyslaw Jarema Lewyckyj (urjlew@ecsvax.UUCP) asks:
>In a similar vein to saving values of local variables in subroutines
>across invocations. What does the standard and experience say
>about saving of array shape parameters passed in through an ENTRY
>statement
>    Subroutine xyz
>    dimension  a(m,n)
>     ......
>     x=a(i,j)
>     .....
>     return
>     ENTRY setup(a,m,n)
>     return
>     end
>Setup is called once from some point in the program.
>xyz is called many times from various points in the program,
>not  necessarily from the same routine that calls setup.
>THis works on IBM 370 type systems, MVS, VM with VS Fortran
>compiler, at least in programs where xyz is not overlaid/reloaded.
>This is/was a way of improving performance by eliminating the
>need to pass a,m,n through all the paths needed to include it
>in the xyz call, and also avoiding the additional complexity of
>getting it done correctly. 

1. The standard prohibits this.

2. You would be well advised to observe the standard in this matter.  Even
   on machines where this "works", it only works some of the time.  The problem
   is that your optimizer doesn't have a clue that calls to xyz could
   reference or define a, n, and m; in an effort to speed up your code, the
   contents of these variables may be different from what you would expect.
   For example, if the code to define the values in a comes after the call to
   setup, the optimizer may find no apparent uses of those values and eliminate
   that code!