Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!clyde.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!arizona.edu!cerritos.edu!usc!samsung!sol.ctr.columbia.edu!lll-winken!sun-barr!newstop!exodus!boise.Eng.Sun.COM!wsb From: wsb@boise.Eng.Sun.COM (Walt Brainerd) Newsgroups: comp.lang.fortran Subject: Re: SAVEing FORTRAN variables Summary: DATA entities are not saved Message-ID: <8042@exodus.Eng.Sun.COM> Date: 15 Feb 91 19:53:32 GMT References: <1991Feb15.000230.18585@news.arc.nasa.gov> <1991Feb15.172635.17261@craycos.com> Sender: news@exodus.Eng.Sun.COM Lines: 46 In article <1991Feb15.172635.17261@craycos.com>, pmk@craycos.com (Peter Klausler) writes: > In article <1991Feb15.000230.18585@news.arc.nasa.gov> chau@xenon.arc.nasa.gov writes: > >I am looking for a tool which scans FORTRAN source code and identifies > >variables which should be saved. > > > >This is a simple example of a FORTRAN source code that needs to scan > >and insert a SAVE statement: > > > > subroutine sub (val) > > integer val, i > > data i/10/ > > > > 10 val = val * i > > i = i -1 > > goto 10 > > return > > end > > > >When subroutine sub is called the second time the value of i may not be the > >same. Therefore, it needs to have a SAVE statement to make i become static. > > Variables that are initially defined with a DATA statement are static, and > don't need a SAVE statement. This is not correct, in general, though it may be true for some implementations. The rules state (17-4, 45-53) that "The execution of a RETURN statement or an END statement within a subprogram causes all entities within the subprogram to become undefined except for the following: . . . (b) Initially defined entities that have netiher been redefined nor become undefined . . ." In the example, i gets redefined, so its value upon reentry is up for grabs. This was done purposely to allow implementations to either save the old value or reinitialize upon reentry. Thus the programmer must use a SAVE statement to be portable if that is what is desired. -- Walt Brainerd Sun Microsystems, Inc. wsb@eng.sun.com MS MTV 5-40 Mountain View, CA 94043 415/336-5991