- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Recently, we are upgrading our old software from F77 to F95. One issue is to replace the old common block with module. I have a question:
In the module, should every variable has the attribut "SAVE" to share the value among different procedures? Or, it's not necessary.
I have just done some experiment with and without "SAVE" attribute. The software works same. From experiment, it seems the "SAVE" attribute is not necessary. I wonder, is it the way of Fortran stardards? or it depends on the compiler.
Thanks for your hint!
Feipeng
In the module, should every variable has the attribut "SAVE" to share the value among different procedures? Or, it's not necessary.
I have just done some experiment with and without "SAVE" attribute. The software works same. From experiment, it seems the "SAVE" attribute is not necessary. I wonder, is it the way of Fortran stardards? or it depends on the compiler.
Thanks for your hint!
Feipeng
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran standard says that module variables retain their definition as long as there is an active program unit that references that module. Theoretically, if you have a program structured like this:
then the variable in module moda could become undefined when sub1 returns. If the main program also did a "use moda", then this would not be an issue. In practice, most compilers, including Intel's, allocate such variables statically and they retain their values.
It doesn't hurt to use SAVE in this case. One never knows what future compilers might do.
module moda
integer moda_variable
end module moda
program test
call sub1
call sub2
end
subroutine sub1
use moda
moda_variable = 1
end
subroutine sub2
use moda
print *, moda_variable
end
then the variable in module moda could become undefined when sub1 returns. If the main program also did a "use moda", then this would not be an issue. In practice, most compilers, including Intel's, allocate such variables statically and they retain their values.
It doesn't hurt to use SAVE in this case. One never knows what future compilers might do.
Message Edited by Steve_Lionel on 03-10-2006 10:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot!
Feipeng
Feipeng

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page