Re: Strange behavior using a module which uses another module



deltaquattro wrote:
On 31 Lug, 18:51, ka...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx (Steven G. Kargl)
wrote:
In article <ba7b849c-3c46-4bc8-98e4-9f48fed9c...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
deltaquattro <deltaquat...@xxxxxxxxx> writes:

it's me again :-) I'm testing my function libraries against a standard
library and I don't understand what's happening. The libraries I
developed are called md_Jacobi and md_Global_funcs. The standard
library function is dgamma.f from SPECFUN.
module md_Global_funcs
private ! Make all symbols private
public dgamma, ... ! Only make the desired symbols public.
[..]
1) I was surprised that main was able to access gamma, lgamma and
factorial, defined in md_Global_funcs, since main only uses md_Jacobi
and not md_Global_funcs. However, I looked at MRC and found that since
md_Jacobi uses md_Global_funcs, then main has access to it also. Is it
possible to let a program unit A use a module B, without having access
to any module used by B unless explicitly used by A?
See above.

Maybe my example wasn't very clear. Obviously, in the example I
posted, in order for main to work, it must have access to dgamma by
host association, and yours is a way to allow it. However, question 1)
wasn't related exactly to this case, but to a similar, however
slightly different one. Suppose I have a program unit A, accessing
module B, and module B accessing module C:

program A
use B
end program A

module B
use C
..
end module B

module C
..
end module C

I want A to have access only to entities defined in B and not to C,
and I don't want to do it like this:

module B
use C
private :: sub1_C, sub2_C,...
..
end module B

otherwise each time I modify C I have to modify B. I'd also rather not
do this (suggested by Tobias), unless there's no other way:

module B
use C
private
public :: sub1_B, sub2_B,...
..
end module B

You want to specify very particular access rules, but without writing anything? (I'm just kidding....)

The way I do it is using Tobias' method:

module B
use C
private
public :: sub1_B, sub2_B,...
..
end module B


otherwise I'll have to increase the PUBLIC list each time I modify B.

Yes, that is correct. And the PUBLIC list is explicit documentation of what you want to be publicly accessible from that module. That's two birds with one stone.

BTW, I also hope you are using an ONLY clause for your "Use C" in module B, and your "Use B" in program A? That will let maintainers know from whence various symbols come.

Clearly this is less of a problem because the modification stays local
to B, however it's a possible source of error, so if there's an
"automatic" way of declaring only all entities in C as PRIVATE, I
believe it would be better.

How would some sort of "automatic" method that you want be less prone to error?

cheers,

paulv
.



Relevant Pages

  • Re: cant use udt in a class?
    ... Private Sub Command1_Click ... Another quirk is that you can declare Properties in a .BAS module, ... So you could actually expose functions from modules and hide the ... This would be essential when you went to exposing these modules in libraries ...
    (microsoft.public.vb.general.discussion)
  • Re: use of backward single quote in procedure names, was: DST (summer time) offset
    ... On Mar 9, 1:54 pm, Jeremy Nicoll - news posts ... more libraries share the same name. ... Of course if the number of 'private' variables is small (or they are ... addressed by using a RETURN parameter rather than global variables. ...
    (comp.sys.acorn.programmer)
  • Re: Document Libraries
    ... "Steve Smith" wrote: ... add new users to access their private documents if they ... libraries for other users, only their own... ... and put some documents only meant for that specific employee... ...
    (microsoft.public.sharepoint.portalserver)
  • Re: /proc/*/statm, exactly what does "shared" mean?
    ... > Does this only reflect libraries that are dynamically loaded? ... > If there is a place where I might find documentation that is more clear ... from executable or library or shared memory or file mmap), ... private pages which currently have swap allocated (so they're also ...
    (Linux-Kernel)
  • Re: Google version of roff History
    ... >> Although the notion of a private lending ... galleries and libraries in Britain (including the big ... If the www had been invented by an American rather than an Englishman ...
    (rec.outdoors.fishing.fly)