Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

g77...Does Data cause variables to be static 1

Status
Not open for further replies.

BPMan

Programmer
Jun 25, 2002
163
0
0
US
in fortran variables become static if you initialize them in there declaration. When you initialize a variable using DATA is this considered to be in the declaration, e.g. does it cause the variable to become static.

I am using fortran 77
thanks
 
Depends on what you mean by static. Possible meanings

The value is where you left it when the routine is re-entered. This used to be the case on Fortran IV but it changes from compiler to compiler. If you want it to remain the same on re-entry, put it in a common block. That can always be initialized with a BLOCK DATA segment.

There is only one instance of the variable. If you have a recursive routine, this can cause problems. Some implementations are stack based so the variables are not 'static'.
 
i am using the gnu compiler version 3.2.2, so i am compiling with g77. And by static i mean that the value remains the same, so after the function leaves and then comes back the value remains the same. Is this the case if i do this:

REAL Variable

DATA Variable / 10 /

would this become static?
also if i call equivalence would it become static?

thanks
 
If a variable is initialized with a DATA statement it will be "static" (in fortran parlance, it will have the SAVE attribute). When the program unit containing it is entered for the first time, it will have the value specified in the data statement and for subsequent entries, it will have the value it had when the program unit was last exited. See also the SAVE statement, the PARAMETER statement and the COMMON statement.


CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top