Path: utzoo!utgpu!attcan!uunet!husc6!ogccse!blake!uw-beaver!fluke!ssc-vax!dmg From: dmg@ssc-vax.UUCP (David Geary) Newsgroups: comp.lang.c Subject: Re: Subroutine layout in C Keywords: Here's a couple of handy macros... Message-ID: <2459@ssc-vax.UUCP> Date: 5 Jan 89 17:44:15 GMT Organization: Boeing Aerospace Corp., Seattle WA Lines: 57 Frank Reiter writes: >In article <2800002@uxg.cso.uiuc.edu> phil@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 ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~