home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!cs.utexas.edu!wupost!gumby!destroyer!ubc-cs!fs1.ee.ubc.ca!davem
- From: davem@ee.ubc.ca (david michelson)
- Subject: Re: programming style question
- Message-ID: <1992Aug16.221725.6760@ee.ubc.ca>
- Organization: University of BC, Electrical Engineering
- References: <1992Aug16.195651.25319@news.Hawaii.Edu>
- Date: Sun, 16 Aug 1992 22:17:25 GMT
- Lines: 66
-
-
- 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?
-
- For example, consider the subroutine FOO with entry point FOOC:
-
-
- SUBROUTINE FOO(X,A,B,C)
-
- [lots of stuff that depends only on A and B
-
- G = ....
- H = ....
-
- ENTRY FOOC (X,C)
-
- X = G * C + H
-
- RETURN
- END
-
-
- Is this a dangerous way to write FOO if I want to do this:
-
-
- PROGRAM OPTIMIZE
-
- A = ...
- B = ...
- C = ...
-
- CALL FOO(X,A,B,C)
-
- * find the value of C which is a root of X with A and B fixed
-
- [lots of code] <----
- |
- CALL FOOC (X,C) <-------------------- the values of G and H
- | are "remembered" from when
- | FOO() was called.
- [loop back until done]--
-
- WRITE(6,*) 'The root is... ', C, ' !'
-
- END
-
- --------------------------------------------------------------------
-
-
-
- There are many ways that I can accomplish the desired result but
- this seems to be the easiest way to "speed up" my existing code
- and it seems to work, in principle, on the PC-based WATFOR77
- compiler.
-
- Does the Fortran standard specify that compilers will generally
- behave this way? Would I look foolish and look like a "hack"
- programmer if I were to describe this in the documentation to
- my program?
-
- (ΒΌ the real issue! :-)
-
- Looking forward to your thoughts on the matter.
-
- Dave Michelson "davem@ee.ubc.ca"
-