home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / fortran / 4258 < prev    next >
Encoding:
Text File  |  1992-11-10  |  2.0 KB  |  48 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!rational.com!voltaire!davidm
  3. From: davidm@voltaire.Rational.COM (David Moore)
  4. Subject: Re: Whats the difference between STATIC variables and SAVE variables?
  5. Message-ID: <davidm.721420889@voltaire>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <1992Nov7.161830.7705@netcom.com> <davidm.721341404@voltaire> <BxHG3I.M8r@ux1.cso.uiuc.edu>
  9. Date: Tue, 10 Nov 1992 18:41:29 GMT
  10. Lines: 36
  11.  
  12. ercolessi@uimrl3.mrl.uiuc.edu (furio ercolessi) writes:
  13.  
  14. >In article <davidm.721341404@voltaire>, davidm@voltaire.Rational.COM (David Moore) writes:
  15. >|>I have seen programs which assume that parameters passed once will remain
  16. >|>bound on subsequent calls to entry statements which lack those parameters.
  17. >|>For example, this is sometimes used to allocate memory dynamically. When you
  18. >|>find such a program, locate the original card deck, drop from the top of a tall
  19.  
  20. >if you use SAVE, what's wrong with this technique ?
  21. >you can do poor man's "packages".  i find them very useful when you
  22. >have data that you do not want to expose to the whole world, and you want
  23. >to act on them in many ways.  example:
  24.  
  25. >    call histogram_initialize(n,xmin,xmax)
  26. >    ...
  27. >    do i=...
  28. >        ...
  29. >        call histogram_accumulate(x(i))
  30. >        ...
  31. >    enddo
  32. >    call histogram_output
  33. >        
  34. >and the histogram array (SAVEd, of course) is local to the 'histogram' package, 
  35. >which is a single routine with three entry points.
  36. >I have this in a lot of programs and find it useful.
  37.  
  38. The point is that the actual-formal binding goes away; you can make copies of
  39. the values in SAVE variables; this is fine, but if you tried to use "n",
  40. "xmin" and "xmax" in histogram_accumulate or _output, on most compilers, they
  41. will no longer be bound. Any program that does assume they remain bound is
  42. not only non-conforming, but it relies on parameters being passed in a 
  43. particular (and rather inefficient) way; namely that an array of parameter
  44. pointers is statically allocated and written into whenever the routine is
  45. called. 
  46.  
  47. Risc compilers will typically pass parameters in registers.
  48.