delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/29/18:52:21

Mime-Version: 1.0
To: joebarn AT concentric DOT net, djgpp AT delorie DOT com
From: Nate Eldredge <nate AT cartsys DOT com>
Subject: Re: .H Files?!?!?!??!
Date: Wed, 29 Apr 1998 15:47:05 -0700
Message-ID: <19980429224701.AAA11144@ppp123.cartsys.com>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019