C function prototyping and large projects

Frank Swarbrick swarbric at tramp.Colorado.EDU
Sat Sep 17 09:51:51 AEST 1988


In article <24 at motto.UUCP> russ at motto.UUCP (Russell Crook) writes:
>We are just starting to use function prototypes, and are looking for
>suggestions on how to use them.
>
>We know that the Microsoft C compiler can automatically generate
>function prototypes.  Where do you go from there?  When developing
>a large program, composed of many source files, how do you 
>make sure each file picks up the right prototypes for the functions
>it uses?  Are there conventions about where prototypes are stored -
>do you put them in '.h' files, or right in the source file, or
>somewhere else?  Do you put all the prototypes for an entire program
>in one file, or do you use some means of only picking up the ones
>which are needed?  If you put them all in, does it affect compile
>time significantly?

Well, I've only been using C for a little over a year, so I've always
had a compiler that uses prototypes.  This is probably why it's so hard
for me to understand why people find them so hard to use.

ANYWAY...  I put all of the prototypes for non-static functions in a
separate header file and then include it.  For all the static (local to the
file) functions I write them in the file itself.  Here is an example.

-------------------------
/* myfile.h */
void lalaland(void);
void zzz(void);
-------------------
/* myfile.c */

#include "myfile.h"

static void foofoo(void);

void main()
{
   lalaland();
   zzz();
}

void lalaland()
{
   /* stuff */
}

void zzz()
{
   /* more stuff */
}

static void foofoo()
{
   /* local stuff */
}

>Do you regenerate the prototypes automatically, every time you rebuild
>or whenever the source file changes, or what?

I'm not quite sure what you mean.  The header files are compiled every
time they are #included, yes.  It may waste a few seconds, depending
on how large the header file(s) is(are).

Frank Swarbrick (and, yes, the net.cat)              | "1001001 -- S.O.S.
University of Colorado, Boulder                      |  1001001 -- in distress
swarbric at tramp.Colorado.EDU                          |  100100"
:...!{ncar|nbires}!boulder!tramp!swarbric            |                    -Rush 



More information about the Comp.std.c mailing list