[J3] Suggestion about variables accessed by use association
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Thu Nov 8 08:18:01 EST 2018
My (often grossly incorrect) intuition is that this ought to work and even be relatively easy to implement. Even if it failed to guard against modifications, the PROTECTED would serve as a useful indicator to those reading the code as to the intent.
OTOH, the number of public module variables (as opposed to types and procedures), has generally plummeted to a very small number in well-encapsulated Fortran code. (OO mostly lets me make the procedures private as well.) And, most of the cases I can think of for wanting this feature would be equally served by having PROTECTED in the module that declared the variable in the first place.
Can you give us a (motivating) use case where you would want the PROTECTED in some modules while wanting to allow other modules to modify said variable?
- Tom
> On Nov 7, 2018, at 9:31 PM, Van Snyder via J3 <j3 at mailman.j3-fortran.org> wrote:
>
> A colleague remarked that he'd like to be able to access module
> variables by use association, and announce that the using scoping unit
> intends not to change them, so the compiler could produce an error
> message if they appear in a variable-definition context.
>
> He suggested adding INTENT(IN) (or some other annotation) to the USE
> statement. I told him I don't think that's viable because the same
> variable might be accessed some other way on which the path of access
> doesn't have that annotation. Or if it's accessed at module scope, and
> not made private, it might thereafter be accessed by use association
> into another scoping unit, wherein it might not have that annotation,
> etc.
>
> He then suggested allowing to add the PROTECTED attribute (or a new
> attribute spelt differently) to a variable accessed by USE (and maybe
> host) association, in any scoping unit, without declaring a new
> variable, as we do for ASYNCHRONOUS and VOLATILE. If it's the PROTECTED
> attribute, and the attribute is conferred at module scope, it would have
> the current effect w.r.t. accesses from that module by USE association.
> If it's not protected where it's initially declared, it could be changed
> by procedures within the using module. If the attribute is conferred in
> a scope other than a module, it could not appear in a
> variable-definition context.
>
> This is a bit late to add to our work program, unless we decide it fits
> under an existing rubric.
>
> It seems like such an idea ought to work, but is it actually workable at
> all?
>
>
More information about the J3
mailing list