[prog] APIs for dummies?

Akkana Peck akkana at shallowsky.com
Thu Sep 18 10:17:53 EST 2003


Hamster writes:
> Create a single file containing the functions you wish everyone to be able
> to access, and then when ever anyone wants to use those functions, they just
> call that file from whatever programming theyre writing.
> 
> If its not clear what I mean, here's a silly example:
> 
> I have one file called circles.fun, in it are individual routines for
> finding the circumference, area, radius etc of a circle.
[ more detail snipped ]
> I think this how #include works in C, but dont quote me on that!

Yes, this is how it works in C and C++ too, though there's a standard
mechanism for it: files with a .h extension (called "header files" or
"include files") are files containing function "prototypes": in other
words, the specifications on how to call each function and what
arguments they take (and, ideally, also comments explaining a bit
more about how to use the function and what it's for).

So in C, you might put all your circle prototypes in circle.h, and then
if graphics.c needs to use the circle routines, it just adds the line
#include "circle.h"

	...Akkana


More information about the Programming mailing list