Hidden routines
Dave Jones
djones at megatest.UUCP
Fri Dec 23 09:31:59 AEST 1988
> I want to write a subroutine in C, called S. I want S to be known outside.
> I also want to have two subroutines X and Y to be known ONLY to S
> (not known outside of S). Either can be called by S, and each calls
> the other in a recursive way. I also need to share several variables
> entirely within this context (shared between S, X, Y). They can be
> static. There will only be 1 instance of S (and therefore also of X
> and Y, but that should be hidden). Main program M should be able to
> call S, but any references to X and Y will not be resolved by the
> module S. How do I lay out the arrangement of source for S? An
> example would be appreciated. Thanks.
You should read a textbook on C programming. I recommend the classic
Kerningham and Richie.
The only reason I am answering is that I saw some really awful advice in
another reply.
(That sounded a little grumpy. It was not meant to be.)
Now then... The instructions are contradictory.
"two subroutines X and Y to be known ONLY to S"
"each calls the other in a recursive way"
"any references to X and Y will not be resolved by the module S"
Hum. The way I interpret it, here's what you want:
static foo X();
static foo Y();
static foo A;
static
X()
{
A = Y();
}
static
Y()
{
A = X();
}
S()
{
A = X();
A = Y();
}
Complile main() in a separate file and declare S() as "extern" in
that file.
More information about the Comp.lang.c
mailing list