l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2002 Jul 18 09:11

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] C header files question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] C header files question



On Wed, 17 Jul 2002, Peter Jay Salzman wrote:

> during the course of writing a C program, often i'll change an
> implementation of the way i do things.
> 
> functions get added and deleted, but often i'll forget what header file
> was added for a particular function.
> 
> i know there are header files which aren't needed anymore.
> 
> is there a utility that lets you know which header files aren't needed
> for a particular file of C code?

Sounds like something a "lint" or compiler might do, but lclint doesn't
appear to do this.

I try to keep the total number of includes in any given file to a minimum.
Commenting a header you suspect of being unnecessary and attempting to
recompile is an effective solution for small numbers of headers.

One way to minimize headers is to define your own "modules":

+-myio.h------------+
| int do_input();   |
| void do_output(); |
+-------------------+

+-myio.c-------------------------------------+ +-mytoplevel.c------+
} #include "myio.h"                          | | #include "myio.h" |
| #include <stdio.h> /* scanf(), printf() */ | | int main() {      |
| int do_input() { ... }                     | |  do_input();      |
| void do_output() { ... }                   | |  ...              |
+--------------------------------------------+ |  do_output();     |
                                               +-------------------+

stdio.h here is representative of some large, complicated headers
associated with a powerful library.

While this example may seem trivial, in a large program the fact that only
myio.c depends on some huge external library can have far reaching
effects.  One effect is shortened compilation for all the modules that
depend on myio.h but don't directly include stdio.h.  This also localizes
the dependency, so if you decide to use <gtk-1.2/gdk/gdk.h> instead of
<stdio.h>, you don't even have to recompile any of the rest of your object
modules.  From a complexity control perspective, this is a good thing. :)

If you have more than 5 or 10 includes, you should probably ask yourself
if you are doing too much in one file.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.