Aleksandar Donev writes:
> Module A defines public type tA
>
> Module B has a global PRIVATE, USEs A, and defines a public type tB with a
> component of type tA. It *does not* export tA as PUBLIC.
>
> Does this automatically (implicitly) make tA PUBLIC in tB?
No. The only thing that *EVER* makes something implicitly public is
the unqualified PUBLIC statement, which makes everything implicitly
public.
> type tA is needed in order to
> deal with objects of type tB
No it isn't, depending on what you mean by "deal with". The compiler
knows what to do. I think you may be missing a fundamental point
about public/private. Public/private have to do with the namespace;
that is *ALL*. If the type tA is not public, then that just means
that you can't use that name. So you can't do things that would
require you to use that name (such as declaring something to be of
that type). If you aren't going to use the name, then you don't
need public accessibility. You are *NOT* constrained against
having access to a variable just because you don't have access to
the name of the type of the variable. The compiler knows what
to do anyway - you need public access to the name of the type only
if *YOU* need to explicitly use that name.
> (this I assume is the reason why public types
> cannot have components of private type).
That's a complicated question, which is the subject of more than
one interp. For the most part, the restriction against that was
just a misguided attempt to do something that it didn't succeed in
anyway. It caused far more problems than it solved. The interp
questions related to some of the problems it caused. Early
versions of some compilers prior to the interps got it wrong,
with the effect that private types were all but unusable in
practice.
Subtle but *CRITICAL* point in interpreting the restriction:
Something is PRIVATE only if it is private in the module that
defines it in the first place. You can *NEVER* make something
private in a module that obtains access to it via USE. I find
the name PRIVATE unfortunate and misleading, but it is too late
to change now. The PRIVATE statement doesn't actually make
something private; it just declares that it is "not a public
entity of the module". If you have trouble seeing the distinction,
then you have lots of company, but it is nonetheless critical.
Even though it is not a public entity of that module, it can
still be a public entity of some other module. Indeed, you couldn't
have USE'd it in the first place if it weren't.
F2k drops the restriction, which gets rid of all the above
confusing subtlety,
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|