Re: save attribute for module variables



| Beg to differ: it can be made to matter with all compilers.  The
| issue arises when a module variable is of a user-defined type
| with default initialization.  In that event, every time the
| variable comes into scope after being out of scope, the default
| initialization should be applied.  Since the standard doesn't
| want the Fortran processor to have to keep track of when a
| module goes out of scope, it evades this requirement by instead
| requiring a module variable of a user-defined type with default
| initialization to be given the SAVE atribute, either directly
| or via an explicit initialization.

James, care to expand? Is it *illegal* to have the described
situation without the variable having SAVE attribute, or is it required that the compiler should apply the default initialisation
on re-entering the scope? I just tried the situation you described
with CVF6.6C and presence of SAVE made no difference (nor the compiler complained about it, even with F95 standard checking). I can try IVF9.0 also.

I understand James as saying the following: If the standard did not require initialized module variables to automatically be SAVEd, you could tell, by modifying such a variable, letting the module go out of and back into scope, and then examining the value, tell whether your compiler implemented the resetting of modules as they leave and enter scope, or not. As the standard did not want this implementation difference to become visible - this is what I believe is called a post hoc rationalization - the standard says that initialized module variables - as indeed, if I'm not mistaken, all initialized variables - automatically acquire the SAVE attribute. Thus, it makes no difference to the program or the compiler whether you add the SAVE statement or attribute in such cases or not - except, perhaps, to remind as the reader of the code that this attribute is already implied by the initialization.

	Jan
.



Relevant Pages

  • Re: save attribute for module variables
    ... > require "reinitialization" of objects when they go out of scope. ... > it is not a test of the standard. ... initialization to have the SAVE attribute: ... to be consistent with the above about module variables, ...
    (comp.lang.fortran)
  • Re: save attribute for module variables
    ... With some other compiler ... | variable comes into scope after being out of scope, ... | initialization should be applied. ... Since the standard doesn't ...
    (comp.lang.fortran)
  • Re: save attribute for module variables
    ... >> | variable comes into scope after being out of scope, ... >> | initialization should be applied. ... Since the standard doesn't ... > and then examining the value, tell whether your compiler implemented the ...
    (comp.lang.fortran)
  • Re: save attribute for module variables
    ... || it required that the compiler should apply the default initialisation ... | initialized module variables - as indeed, if I'm not mistaken, all initialized ...
    (comp.lang.fortran)
  • Re: save attribute for module variables
    ... what does the standard say about module variables with explicit ... initialization and that default initialization. ... You seem to be considering module variables as a special case. ... The standard says essentially nothing about how explicit ...
    (comp.lang.fortran)