"保存"一个共同的块 [英] "Saving" a common block
问题描述
我正在处理一些遗留代码,它广泛使用 COMMON
块,有时使用 SAVE
语句。在查阅了Fortran标准后,它说:
$ b
一个公共块名的出现在一个
SAVE
语句的作用是指定该公共块中的所有实体。
情况确实将一个变量放置在一个公共块中,而不意味着 SAVE
?由于该变量必须在包含该公共块的任何其他程序单元中可访问,因此它怎么可能不是 SAVE
ed?
我必须查看它,因为我的印象和你一样。
似乎只有一个未命名的,所谓的空白公用块中的变量保留整个程序的定义状态。从另一个子程序返回时,未命名的公用块变量未定义,除非另一个当前活动的程序单元包含相同公用块的公用语句。
从标准Fortran 77,但最新的包含类似的措辞):
lockquote
17.3导致实体变为未定义的事件
[ ...]
6.在子程序中执行RETURN语句或END语句会导致子程序内的所有实体都不确定,除了以下内容:
[..] 。]
d。在出现在子程序中并出现在至少一个直接或间接引用子程序的其他程序单元中的命名公共块中的实体
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 SAVE
ed?
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
这篇关于"保存"一个共同的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!