Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Saving" a common block

I'm dealing with some legacy code that uses COMMON blocks extensively and sometimes uses the SAVE statement. After consulting the Fortran standard, it says:

The appearance of a common block name preceded and followed by a slash in a SAVE statement has the effect of specifying all of the entities in that common block.

Under what circumstances does placing a variable in a common block not imply SAVE? Since the variable must be accessible in any other program unit that includes that common block, how could it not be SAVEed?

like image 953
mgilson Avatar asked Feb 23 '12 23:02

mgilson


1 Answers

I had to look it up, because I was under the same impression as you are.

It seems that only variables in an unnamed, so-called blank, common block retain their definition status across the entire program. Unsaved variables in a named common block become undefined on return from a subprogram, unless another currently active program unit includes a common statement for the same common block.

From the standard (Fortran 77, but the latest one contains similar wording):

17.3 Events That Cause Entities to Become Undefined
[...]
6. The execution of a RETURN statement or an END statement within a subprogram causes all entities within the subprogram to become undefined except for the following:
[...]
d. Entities in a named common block that appears in the subprogram and appears in at least one other program unit that is either directly or indirectly referencing the subprogram

like image 134
eriktous Avatar answered Oct 01 '22 13:10

eriktous