[prog] [C/C++] what to put in header files.

Conor Daly c.daly at met.ie
Thu Sep 26 08:19:46 EST 2002


On Wed, Sep 25, 2002 at 01:49:23PM -0700 or thereabouts, Laurel Fan wrote:
> On Wed, Sep 25, 2002 at 10:27:43AM +0200, Dan Richter wrote:
> > Sometimes at the beginning teachers tell students to write header files 
> > like this:
> > 
> > #ifndef FOO_H
> > #define FOO_H
> > 
> > /* Interface stuff here. */
> > 
> > #include "foo.c"
> > #endif
> 
> I don't get it... how is that simpler than
> 
> foo.h:
> #ifndef FOO_H
> #define FOO_H
> 
> /* Interface stuff here. */
> 
> #endif
> 
> foo.c:
> #include "foo.h"
> 
> ?

I'd assume the idea is that with multiple source files, you just 
#include foo.h
in the main.c source file and end up with just a single filename on the
compiler commandline.  So, instead of 

gcc -lm -o prog main.c foo.c bar.c

you have 

gcc -lm -o prog main.c

and main.c includes foo.h and bar.h which, in turn, include foo.c and bar.c

It certainly looks simpler to the new student especially in comparison to
their first look at a Makefile!

Conor (who learned to use Makefiles just last year...)
-- 
Conor Daly 
Met Eireann, Glasnevin Hill, Dublin 9, Ireland
Ph +353 1 8064276 Fax +353 1 8064247
------------------------------------
bofh.irmet.ie running RedHat Linux  8:15am  up 13 days, 20:58,  8 users,  load average: 0.10, 0.04, 0.02


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept 
for the presence of computer viruses.


**********************************************************************




More information about the Programming mailing list