home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!rational.com!voltaire!davidm
- From: davidm@voltaire.Rational.COM (David Moore)
- Subject: Re: Whats the difference between STATIC variables and SAVE variables?
- Message-ID: <davidm.721341404@voltaire>
- Sender: news@rational.com
- Organization: Rational
- References: <1992Nov7.161830.7705@netcom.com>
- Date: Mon, 9 Nov 1992 20:36:44 GMT
- Lines: 47
-
- jchauvin@netcom.com (John H. Chauvin) writes:
-
- >Is there a difference between variables defined as STATIC and those defined
- >with the save statement? How can I tell if a program requires the compiler
- >option STATIC? How does the STATIC option effect program execution speed?
- >Should I try and avoid using it?
-
- I assume that by STATIC you are referring to a compile time flag. This flag
- is provided by many implementors because old Fortran programs assume that
- local variables retain their values from one call of a subroutine to another.
-
-
- Such programs are non-conforming. Using the save statement makes the
- programs conforming - using the flag does not.
-
- On most machines on which this is an issue, using the STATIC flag will
- often cause programs to run slower. Most implementors, knowing that there
- are a lot of non-conforming programs in existence, will not implement locals
- as dynamic variables unless there is a performance reason to do so. Typically,
- they run faster because:
-
- 1) Scalars can be allocated into registers.
- 2) Address offsets are short (stack relative) rather than full
- machine-length addresses.
-
- So, this is another eason for using SAVE rather than the compilation flag.
-
- REMARKS:
-
- I have seen programs which assume that parameters passed once will remain
- bound on subsequent calls to entry statements which lack those parameters.
- For example, this is sometimes used to allocate memory dynamically. When you
- find such a program, locate the original card deck, drop from the top of a tall
- building, and see if you can erase all the disk copies before the deck hits
- the ground (hint; remove the rubber bands)
-
- I once saw a compiler which dynamically allocated common blocks. It ran like
- a dog since the common block allocator was hopelessly slow.
-
- I believe the constructors of this piece of nonsense have since produced a much
- better compiler. Still, technically, dynamic common blocks are standard conforming
- (I could have lived with them too, except for the performance hit).
- Make sure you SAVE your common blocks if they should be persistent.
-
-
-
-
-