home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!gatech!hubcap!jtbell
- From: jtbell@hubcap.clemson.edu (Jon Bell)
- Subject: Re: programming style question
- Message-ID: <1992Aug17.013714.23963@hubcap.clemson.edu>
- Organization: Presbyterian College, Clinton SC
- References: <1992Aug16.195651.25319@news.Hawaii.Edu> <1992Aug16.221725.6760@ee.ubc.ca>
- Date: Mon, 17 Aug 1992 01:37:14 GMT
- Lines: 27
-
- In article <1992Aug16.221725.6760@ee.ubc.ca> davem@ee.ubc.ca (david michelson) writes:
- >
- > Is it dangerous or poor practice to assume that the variables
- > in a subroutine will retain the values assigned in the immediately
- > previous execution the next time it is called?
- >
-
- [example deleted]
-
- Yes, it is dangerous to assume this. With most compilers, it will work OK,
- but on _some_ systems, local variables in a subroutine will get thrown away
- when you return to the calling routine. It depends on whether local
- variables are allocated as static storage, or on a "run-time stack."
-
- It may work fine on your current machine, but it you port the code to another
- machine, you run the risk that the code will fail.
-
- Fortunately, there's an easy solution. Simply put a SAVE statement at
- the beginning of the subroutine, and list all the variables whose values
- you want to preserve between calls.
-
- This is all covered in the Fortran 77 standard, BTW.
-
- Jon Bell / Dept. of Physics & Computer Science / Presbyterian College
- Clinton SC / jtbell@presby.edu
-
-
-