On Tue, 2 Dec 1997 [log in to unmask] wrote:
> I found no prohibition and it works with three compilers, so I assume
> it's OK to USE a MODULE, say, once directly and once indirectly (by
> using another MODULE which uses the first one).
>
> I think this is a good idea. For example, I might be doing some
> numerical stuff USEing some module, and then later decide I need some
> more stuff, and USE another module which (perhaps unknown to me) USEs
> the first one. Fine---things work like I want and I guess there is no
> ambiguity involved.
>
> However, in the mental model if inserting the MODULE information at the
> place of the USE statement, one could think that one would get a warning
> saying that something has been multiply defined. Sure, the compiler
> should be able to catch this and do things correctly and the ones I
> tested (Digital, IBM, SUN) do, but can I DEPEND on this behaviour?!
>
> In the books I consulted (Digital documentation, Michel, M&R) I couldn't
> find any explicit permission of this (or, more, something saying that I
> can count on it) in the obvious places. (The Digital documentation
> describes the behaviour of two USE statements within one scoping unit,
> and, combined with the information about host association it would seem
> that my example above would be two USE statements in the same scoping
> unit, and thus the behaviour should be as described and as my tests
> show. However, USE is such an important concept that I would have
> expected such information to be discussed where USE is discussed, since
> perhaps the concept of host association by using a module which uses
> another (as opposed to, say, internal procedures) is not immediately
> obvious when thinking about USE.)
You can remove some potential problems with the USE of module by inserting
PRIVATE statements, e.g.
MODULE A
! some stuff
END MODULE A
MODULE B
USE A
! some other stuff
END MODULE B
MODULE C
USE B
! even more stuff
END MODULE C
Module C has access to A through B. However, if you do
MODULE B
USE A
PRIVATE
PUBLIC :: ! whatever you want to be public
! some other stuff
END MODULE B
then C has only access to the public part of B but not to anything
from A. If you want A you have to USE A in C.
I think the F90 default way of using modules is highly problematic
from a design point of view. Users do not know what is accessible
or not when using a library, even ones they have written themselves
since one cannot remember everything.
F90 should have implemented default PRIVATE in modules from the start,
now it is too late.
I think there is a different rule in one of the subsets of F90, either
ELF or F where using a module more than once is explicitly forbidden.
That is reasonable but forces the mentioned PRIVATE declaration.
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|