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.
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?
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.