Let us look at the examples we used earlier.
int give_three()
{
return 3;
}
void out_one(int i)
{
printf("%d\n",i);
}
float make_real(int i, int j, float r)
{
return (float)(i+j) + r;
}
If we put this sequence into a file called funs.c, say, we can compile this file, to create an object file, funs.o on UNIX. Using the cc compiler on UNIX this would be done as follows
cc -c funs.c
The prototypes for these functions are:
int give_three();
void out_one(int);
float make_real(int, int, float);
If we want to use functions which already exist as linkable object files,
we introduce them to our program as below. The compiler assumes that they
exist in a library and will be linked in before execution. stdio.h,
stdlib.h etc. contain prototypes of standard functions in this form. It
is often convenient to build our own libraries of functions which we can
re-use in future programs.
void PrintTwo(int, int); int Larger(int, int);These two declarations could be placed in a header file and introduced with a #include directive. Building and using libraries is described elsewhere in these notes.