Van Snyder wrote:
>
> Aleksandar Donev asked:
>
> > I am wondering if anyone can clarify the effect of the SAVE attribute
> > for global data (i.e. data declared in modules). For example:
> >
> > program main
> > use routines, only : routine
> > call routine()
> > ...
> > call routine()
> > end program main
> >
> > module routines
> > use shared, only : value
> > contains
> > subroutine routine()
> > write(*,*) value
> > value=value+1
> > end subroutine routine
> > end module routines
> >
> > module shared
> > integer, SAVE :: value
> > end module shared
> >
> > Does it matter that there is a SAVE on value. If not, when does it
> > matter.
>
> The standard allows non-saved module variables to disappear when there
> is no procedure accessing the module by use association. In your case,
> any nonsaved variables in the "shared" module could in principle disappear
> between calls to "routine" because there is no "use shared" in your main
> program. I don't know if any compilers take advantage of this feature
> of the standard.
>
> Best regards,
> Van Snyder
Maybe I'm missing something here, but I thought that that access includes indirect
access, i.e. "main" uses "routines" which uses "shared", so then "value" is still in
scope in the main program and remains defined without the save attribute. In
fact, we could have a "print *, value" statement in main, right? Section 11.3.2
page 188 of the f95 standard says "If the local name [of an entity made accessible
by a USE statement] does not appear in either a PUBLIC or PRIVATE statement, it
assumes the default accessibility attribute of that scoping unit." Am I misinterpreting
this? Doesn't this make "value" accessible in "main"?
Bill
--
William F. Mitchell
Mathematical and Computational Sciences Division
National Institute of Standards and Technology
[log in to unmask] http://math.nist.gov/~mitchell
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|