delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/03/18:51:33

From: Tom St Denis <stdenis AT compmore DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Making header file - Newbie question
Date: Wed, 03 Jan 2001 23:38:46 GMT
Organization: Deja.com
Lines: 48
Message-ID: <930d66$s3$1@nnrp1.deja.com>
References: <3A53AA94 DOT 911 AT vic DOT ozland DOT net DOT au>
NNTP-Posting-Host: 24.156.37.224
X-Article-Creation-Date: Wed Jan 03 23:38:46 2001 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
X-Http-Proxy: 1.1 x61.deja.com:80 (Squid/1.1.22) for client 24.156.37.224
X-MyDeja-Info: XMYDJUIDtomstdenis
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <3A53AA94 DOT 911 AT vic DOT ozland DOT net DOT au>,
  jgcasey AT vic DOT ozland DOT net DOT au wrote:
> Hi,
>
> I am new to djgpp (<week) although I have dabbled in C and have
> written little assembler programs. My problem is how to save the
> standard functions that I call from main() in a header file so I
> can just inlude them at the beginning without having to scroll
> through them all to get to the latest segment I am working on.
>
> I have scanned as much documentation as I could until my head ached
> but couldn't find anything that actually explained how to do this.
>
> Any pointers in the right direction would be appreciated :)

Header files are just normal text files with .h extensions.  You begin
them with

#ifndef FILENAME_H_
#define FILENAME_H_

extern int myfunc(...);
/* etc... */

#endif

The # tokens are called preprocessor directives.  In this case they
prevent the file from being included multiple times (you replace
FILENAME with the name of the header file).

the "extern int myfunc(...);" is a loose example of a function which is
external (i.e made global from within another object file).

In your main.c (or main C file) just do

#include "filename.h"

and the definitions should become available.


Hope this helps...


Tom


Sent via Deja.com
http://www.deja.com/

- Raw text -


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