home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3054 < prev    next >
Encoding:
Text File  |  1992-08-16  |  2.1 KB  |  77 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!cs.utexas.edu!wupost!gumby!destroyer!ubc-cs!fs1.ee.ubc.ca!davem
  3. From: davem@ee.ubc.ca (david michelson)
  4. Subject: Re: programming style question
  5. Message-ID: <1992Aug16.221725.6760@ee.ubc.ca>
  6. Organization: University of BC, Electrical Engineering
  7. References: <1992Aug16.195651.25319@news.Hawaii.Edu>
  8. Date: Sun, 16 Aug 1992 22:17:25 GMT
  9. Lines: 66
  10.  
  11.  
  12.     Is it dangerous or poor practice to assume that the variables
  13.     in a subroutine will retain the values assigned in the immediately
  14.     previous execution the next time it is called?
  15.  
  16.     For example, consider the subroutine FOO with entry point FOOC:           
  17.  
  18.  
  19.        SUBROUTINE FOO(X,A,B,C)
  20.  
  21.        [lots of stuff that depends only on A and B
  22.  
  23.        G = ....
  24.        H = ....
  25.  
  26.        ENTRY FOOC (X,C)
  27.  
  28.        X = G * C + H
  29.  
  30.        RETURN
  31.        END
  32.  
  33.  
  34.     Is this a dangerous way to write FOO if I want to do this:
  35.  
  36.  
  37.        PROGRAM OPTIMIZE
  38.  
  39.        A = ... 
  40.        B = ...
  41.        C = ...
  42.  
  43.        CALL FOO(X,A,B,C)
  44.  
  45.   * find the value of C which is a root of X with A and B fixed 
  46.  
  47.        [lots of code]     <----
  48.                                |
  49.        CALL FOOC (X,C)  <-------------------- the values of G and H 
  50.                                |              are "remembered" from when
  51.                                |              FOO() was called.
  52.        [loop back until done]--
  53.  
  54.        WRITE(6,*) 'The root is...  ', C, ' !'
  55.  
  56.        END
  57.  
  58.  --------------------------------------------------------------------
  59.  
  60.  
  61.  
  62.        There are many ways that I can accomplish the desired result but
  63.        this seems to be the easiest way to "speed up" my existing code
  64.        and it seems to work, in principle, on the PC-based WATFOR77 
  65.        compiler. 
  66.  
  67.        Does the Fortran standard specify that compilers will generally
  68.        behave this way?  Would I look foolish and look like a "hack"
  69.        programmer if I were to describe this in the documentation to
  70.        my program?
  71.  
  72.        (ΒΌ the real issue! :-)
  73.  
  74.        Looking forward to your thoughts on the matter.
  75.  
  76.        Dave Michelson  "davem@ee.ubc.ca"
  77.