[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Include Collector (may be OT)



On Thu, 27 Jul 2000, Bolan Meek wrote:
> Steve Greenland wrote:
> > 
> > On 26-Jul-00, 15:24 (CDT), Bolan Meek <Bolan.Meek@wcom.com> wrote:
> > > In beginning maintenance & improvement (a.k.a adoption)
> > > of the xmailtool source, I've wanted to collect all the
> > > '#include <whatever.h>' statements that are common to
> > > several of the source files with a Perl script, as opposed
> > > to a error-vulnerable method of doing it by hand.
> > 
> > What are you trying to accomplish? Is this for dependencies in the
> > Makefile?  If so, check out the '-M' (and '-MM') options for gcc, and
> > the section on automatic dependency maintenance in the gmake info file.
> > 
> > If there's some other purpose, please explain...
> 
> No, my desire to eliminate redundancies of
> #include <|"certainfile>|"
> between source files in a source package.  For example, in main.c,
> drawscreen.c, wipefiles.c, and ruleworld.c, there are, in each,
> #include <stdio.h> .  In these _and_ humiliated.c, grovel.c, and
> repent.c,
> there are instances of
> #include <unistd.h> .  In ruleworld.c, there is also
> #include <inet/tcp.h>.
> 
> I want an
> #include "project.h" in each of these files, project.h containing
> #include <stdio.h>
> #include <unistd.h>
> and ruleworld.c to still have the unique inclusion, in addition to
> the common inclusion.
> 
On the risk of being even more off the topic of your post:
You don´t want this !

If you included all header-files you used somewhere in your application into
every source-file, you´d loose track of what part of the program depends on
which other part or library. I don´t know about the size of your proggy, but
beyond a certain size you´ll be happy if your program consists of several
small, easy to handle modules.

Further, it increases compile-time and makes the code slightly unreadable to
others. While I might know what stdio and unistd are, project.h won´t tell me
anything at all, I would expect something like config.h there. If I only needed
printf, I would even consider just giving the prototype and not including the
header at all (but I have no idea what drawbacks might arise from this,eg
portability, changing headers).

BTW: If you stumble across something which can do the opposite, that is scan
for superfluous header-inclusions, feel free to post to me or the list.

regards
uli



Reply to: