Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Placement of SAVE statement within a module

Honari__Siavash
初学者
3,062 次查看

From a past forum discussion concerning the use of the SAVE statement, I know that adding a SAVE statement within the module is certainly the safest bet. However, I'm not sure where exactly to use the statement. For example, I don't know which of the following usages of SAVE statement are correct:

MODULE A
        IMPLICIT NONE
        SAVE
        INTEGER, PARAMETER:: B=0
END MODULE A

or

MODULE A
        IMPLICIT NONE
        INTEGER, PARAMETER:: B=0
        SAVE
END MODULE A

 

Thanks for any info.

0 项奖励
1 解答
Steve_Lionel
名誉分销商 III
3,062 次查看

You don't need to use SAVE in a module, but if you do, anywhere in the specification-part is fine. Note that as of F2008, the words about module data being defined as long as a USE was in scope has been removed - the reality is that module data is implicitly SAVE and the standard now reflects that.

在原帖中查看解决方案

0 项奖励
5 回复数
jimdempseyatthecove
名誉分销商 III
3,062 次查看

SAVE does not belong in modules. Module data is persistent and global to those that USE it.

Jim Dempsey

0 项奖励
Steve_Lionel
名誉分销商 III
3,063 次查看

You don't need to use SAVE in a module, but if you do, anywhere in the specification-part is fine. Note that as of F2008, the words about module data being defined as long as a USE was in scope has been removed - the reality is that module data is implicitly SAVE and the standard now reflects that.

0 项奖励
Honari__Siavash
初学者
3,062 次查看
Thank you, Steve and Jim. I followed some of the old discussions suggesting that it is prudent to use the SAVE statement in the modules to ensure that all the variables are saved. Now if I understand correctly, it is not necessary but hopefully doesn't really hurt, right? Thanks
0 项奖励
Steve_Lionel
名誉分销商 III
3,062 次查看

It doesn’t hurt and is still allowed by the standard.

0 项奖励
Honari__Siavash
初学者
3,062 次查看

Thanks alot

0 项奖励
回复