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

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!gatech!hubcap!jtbell
  3. From: jtbell@hubcap.clemson.edu (Jon Bell)
  4. Subject: Re: programming style question
  5. Message-ID: <1992Aug17.013714.23963@hubcap.clemson.edu>
  6. Organization: Presbyterian College, Clinton SC
  7. References: <1992Aug16.195651.25319@news.Hawaii.Edu> <1992Aug16.221725.6760@ee.ubc.ca>
  8. Date: Mon, 17 Aug 1992 01:37:14 GMT
  9. Lines: 27
  10.  
  11. In article <1992Aug16.221725.6760@ee.ubc.ca> davem@ee.ubc.ca (david michelson) writes:
  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.  
  17. [example deleted]
  18.  
  19. Yes, it is dangerous to assume this.  With most compilers, it will work OK,
  20. but on _some_ systems, local variables in a subroutine will get thrown away
  21. when you return to the calling routine.  It depends on whether local
  22. variables are allocated as static storage, or on a "run-time stack."
  23.  
  24. It may work fine on your current machine, but it you port the code to another
  25. machine, you run the risk that the code will fail.
  26.  
  27. Fortunately, there's an easy solution.  Simply put a SAVE statement at 
  28. the beginning of the subroutine, and list all the variables whose values
  29. you want to preserve between calls.
  30.  
  31. This is all covered in the Fortran 77 standard, BTW.
  32.  
  33. Jon Bell / Dept. of Physics & Computer Science / Presbyterian College
  34. Clinton SC / jtbell@presby.edu
  35.  
  36.  
  37.