Saving a shared block

I am dealing with some legacy code that makes extensive use of COMMON locks and sometimes uses the SAVE statement. After consulting the Fortran standard, he says:

The appearance of a common block name, which is preceded and followed by a slash in the SAVE statement, has the effect of specifying all objects in this common block.

Under what circumstances does placing a variable in a common block not mean SAVE ? Since the variable must be available in any other program module that includes this common block, how could it not be SAVE ed?

+4
source share
2 answers

I had to see because I was just like you.

It seems that only variables in an unnamed, so-called empty, common block retain their definition status throughout the program. Unclosed variables in a named shared block become undefined upon return from a subroutine, unless the other current active program module contains a common statement for the same common block.

From the standard (Fortran 77, but the latter contains a similar wording):

17.3 Events that make entities become Undefined
[...]
6. The execution of the RETURN statement or the END statement within the subroutine causes all entities within the subroutine to become undefined, except for the following:
[...]
e. Objects in a named generic block that appears in a subroutine and is displayed in at least one other program module that directly or indirectly refers to the subroutine

+6
source

Many Fortran 77 era compilers β€œsaved” all local procedure variables, whether or not SAVE was specified. This is a common reason why legacy programs fail with modern compilers that will define undefined variables when they go out of scope, which is allowed by the language standard. It is likely that these old compilers also kept the values ​​of all common variables throughout the program execution time, although this was not required by the language standard.

+3
source

Source: https://habr.com/ru/post/1398143/


All Articles