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

module to replace common block

feipeng
Beginner
594 Views
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
0 Kudos
2 Replies
Steven_L_Intel1
Employee
594 Views
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:


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

0 Kudos
feipeng
Beginner
594 Views
Thanks a lot!

Feipeng
0 Kudos
Reply