Mail Archives: djgpp/1998/04/29/22:23:40
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.
I recommend using a C tutorial of some sort, whether in a book or in a
class. The proper use of header files is a fairly detailed topic that's
not easy to discuss in a simple email or news post. It's also not
DJGPP-specific.
> 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?
Header files declare code that is defined in other source files (or in a
library, which is basically the same thing). Therefore, you put the
function body in another source file which must also be compiled along
with your program. For example, if I have a two-module program: main.c
and driver.c, and there are some functions in driver.c that main.c needs
to use, I would probably write a header file named driver.h containing
all the prototypes needed by main.c. Then, I #include "driver.h" in
both source files, compile each to an object module, and link them
together to produce the final executable:
gcc -Wall -O -g -c main.c
gcc -Wall -O -g -c driver.c
gcc -o program.exe main.o driver.o
This task can be greatly simplified by using a project management tool
like Make or RHIDE, particularly for large projects.
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| ICQ UIN#: 7406319 | http://www.cs.com/fighteer/ |
| ObJoke: If Bill Gates were a robber, not only would he |
| shoot you, but he'd send you a bill for the bullets. |
---------------------------------------------------------------------
- Raw text -