Subroutine layout in C
David Geary
dmg at ssc-vax.UUCP
Fri Jan 6 03:44:15 AEST 1989
Frank Reiter writes:
>In article <2800002 at uxg.cso.uiuc.edu> phil at uxg.cso.uiuc.edu writes:
>>
>> 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.
>Put S(), X(), and Y() in their own file. Declare X() and Y() to be static
>and do the same with any global variables to be accessed only by S(), X(),
>and Y().
>Other modules will be able to call S() but not X() or Y() or any of the static
>variables.
Frank is correct, this is exactly what you want to do. However, I like
to do the following:
#define PRIVATE static
#define PUBLIC
Now, we can declare the functions S(), X(), and Y() thusly:
PUBLIC int S()
{
...
}
PRIVATE int X()
{
...
}
PRIVATE int Y()
{
...
}
And, of course, we can declare external variables in the same manner:
PUBLIC int x,y;
PRIVATE float f,g;
BTW, these macros are not my invention, I first saw them in a book entitled
"Operating Systems Design and Implementation" (I think the title is correct).
A very good book BTW, on the MINIX OS.
David
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ David Geary, Boeing Aerospace, ~
~ #define Seattle RAIN ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list