delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/28/21:14:44

From: "Steven Taylor" <s_taylor AT primus DOT com DOT au>
Newsgroups: comp.os.msdos.djgpp
References: <37CECA25 AT MailAndNews DOT com>
Subject: Re: help with .h files
Lines: 60
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Organization: Internet Primus
Message-ID: <932713671.109589@diddley.primus.com.au>
Cache-Post-Path: diddley.primus.com.au!unknown AT ras393 DOT ports DOT adel DOT primus DOT com DOT au
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Date: Fri, 23 Jul 1999 16:36:34 +0930
NNTP-Posting-Host: 203.134.0.92
X-Complaints-To: abuse AT telstra DOT net
X-Trace: nsw.nnrp.telstra.net 932713669 203.134.0.92 (Fri, 23 Jul 1999 17:07:49 EST)
NNTP-Posting-Date: Fri, 23 Jul 1999 17:07:49 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Normally, I'd say post to the appropriate group, but I'm feeling generous
today.

Here's a brief education.

The purpse of .h files (commonly referred to as header files) is to DECLARE
functions, classes, structs, types, and variables. All of these can be used
by any program that includes the header file.

If you look through a header file, you will not find the actual
implementation of a function, unless it is really small - usually one line.
Even then, it may not be included. All that is provided in a header file, as
far as functions are concerned, are declarations, which is just the first
line of the function. It contains:

1. The return type
2. The function name
3. Parameter list
4. Semicolon.

So where, you may ask, are the functions themselves? The answer is
libraries. A library is a precompiled set of functions that is linked to a
program at compile time. The standard C library is automatically linked in,
but for other libraries, you have to tell the compiler to link them in. It
is no good just including the header file if you don't use the library,
since all the compiler will see is a bunch of unimplemented functions. Some
compilers (I'm not sure about DJGPP) automatically link the standard C++
library if you specify you are compiling a C++ program. The standard C
library is named libc.a, and the standard C++ library is named libstdcxx.a.

Why, you may ask, aren't the complete functions just shoved into the header
files? Well, there are lots of reasons, such as the convenience of being
able to look in a header file to see a list of functions without having to
view the implementation. But the biggest reason I can think of is simply to
reduce compile time. If something reusable works fine the way it is, then
why recompile it all the time? There is no reason. An example is a library I
use called Allegro. On my machine, it takes roughly half an hour to build
the whole library. If the function bodies were put in the allegro.h file,
then everytime I compile my program, it would take half an hour. But, the
allegro library is in the file called liballeg.a (which is a bunch of
precompiled functions) which I just have to link using the -lalleg option.
Normally, it takes less than half a minute.

NOTE: A library file is always named lib*.a, where * represents the name you
pass to the compiler using the -l option.

As for the information you want on header files that come with DJGPP:
DJGPP includes the entire set of standard C and C++ functions. There are
also some extra C functions that have become somewhat of a standard for any
DOS C implementation. If your installation of DJGPP is correct and complete,
just type info libc. This brings up the info program with the libc reference
guide.

As far as cin and cout are concerned, they should do the same with DJGPP as
with any compiler. Keep reading that C++ book! The questions you have asked
here are not DJGPP specific.

- Steven Taylor


- Raw text -


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