Mail Archives: djgpp/1998/04/29/18:52:21
At 04:29 4/29/1998 EDT, Sanchez the Skiing Communist Cactus wrote:
>Sorry if this quesiton is asked frequently, or if the answer is
>painfully obvious... but please answer it anyway.
>
>Ok.... from what I am able to figure out... A C/C++ *.h file
>contains macro/constant Definitions, and Function PROTOTYPES.... my
>only question is: If I were to create a .h file for my own use, where
>do I put the actual function Body?
In another .c file, which you will compile separately and link later. Example:
--file func.h--
int my_function(void);
-- file func.c--
#include "func.h"
int my_function(void)
{
/* body of function */
}
--file main.c--
#include <stdio.h>
#include "func.h"
int main(void)
{
printf("%d\n", my_function());
return 0;
}
To compile this:
gcc -c func.c
gcc -c main.c
gcc -o prog.exe main.o func.o
HTH
Nate Eldredge
nate AT cartsys DOT com
- Raw text -