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

SAVE statement in data module

gelarimer
Beginner
1,638 Views

A past forum discussion concerned the use of the SAVE statement without any objects specified (or blanket SAVE)in data modules. I believe the conclusion of the discussion was that the SAVE statement is not needed in data modules because modern compilers would ensure that the data is saved. Is thiscorrect, or is it good programming practice toinclude the blanket SAVE statement just in case?

Thanks for any info.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,638 Views
I'm not entirely sure what uou mean by "data module". I can tell you that if a local variable has default initialization (DATA or an initialization specified in the declaration) then the standard says that it has the SAVE attribute implicitly. Otherwise, I would recommend using SAVE wherever that's what you want and not rely on compilers to do it for you.
0 Kudos
gelarimer
Beginner
1,638 Views

On page 342 in Chapman's 'Fortran 90/95...', he states, 'You may use modules to pass large amounts of data between procedures within a program. If you do so always include the SAVE statement witin the module....'

However, the previous posts I refered to, 'Save-statement' posted on 03-29-2004, left me a little confused about the use of the SAVE statementwithout a variable list.

For a win32 program, I have a ModuleGlobalswith NOblanket SAVE statement in the MODULE. Some of the variables are initialized in the module and some are not. But, of course I would like them all to be saved.

From your reply, Iunderstand that it would be prudent to use either the SAVE statement (without a variable list), or to use the SAVE attribute for each uninitialized variable in the global module to ensure that all the variables are saved?

If so, is there a preference (SAVE statement, or SAVE attribute)for global modules that have some variables initialized and others not initialized?

Notethat the IVF win32 project template for the globals module did not includea SAVE statement.

Thanks


0 Kudos
Steven_L_Intel1
Employee
1,638 Views
Ah, module variables. Adding a SAVE statement is certainly the safest bet. But if the module is referenced by the main program, then the Fortran standard specifies that the module variables retain their definition (are "SAVEd") no matter what.

On the practical side, our implementation always saves module variables, but if a module is not to be referenced by the main program, then it is a good idea to add SAVE if that's what you want. The project template does use the module in the main program, soi SAVE is not required.
0 Kudos
gelarimer
Beginner
1,638 Views
Thanks Steve, that explanation helps quite a bit.
0 Kudos
Reply