🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3649

Re: #ifndef/#ifdef problems in my header file (conditional header inclusion)

#3649
From: Greg Comeau
Date: Thu, 26 Dec 1996 00:00
50 lines
3613 bytes
In article <gnusenetraub-2412960039190001@dialup52.afn.org> Mauricio Tavares <raub@kushana.aero.ufl.edu> writes:
>        I am finding some very interesting behavior from #define and
>#ifndef/#ifdef.  Let's say that I have a header file called MyHeader.h.  This
>file is included by all my routines (they usually are in separate files).  Now
>that would not be very nice since it would include the very same include files
>(stdio.h and others) over and over again.  So, I thought if I use something
>like
>
>#ifndef MOOSE
>#define MOOSE
>#include <stdio.h>
>#include <X11/Xlib.h>
>#endif
>
>the code would only include *one* copy of these two include files.  What I am
>finding out is that is not the case.  Running C programs that have similar 
>conditional including of header files in gcc (Sparc), Think C (Mac), Borland
>TC++ 3.1 for Windows (PC), and SAS/C (Amiga) results in the same thing.  It
>really seems that the compiler simply *forgets* what was defined in the
>previous .c file and define them all over again.  As a result, my object files
>become unnecessarily large.  Yes, the executable seems to take care of that,
>but still I am using more disk space than I should.  I am open for suggestions
>as usual.

The compiler need only see something called a `translation unit' at the
point you are talking about.  So, yes, indeed, it won't know about
what happened or not in the previous .c file.

Do note that the extra space you are seeing will be symbol table
entries for things like function prototypes and such.  So, yes again,
if b.c uses printf and c.c uses printf, they will both have information
stating their needs for that routine.  That's just the way it works in
the so-called traditional compiler/linker setup.  I guess in a million
lines of code app, this can for sure eat up lots of space, but I never
particularly thought that I'd call this space unnecessarily large.
Especially with just the two headers you refer to.

Anyway, you know your machine and its constraints better than I.
As such, perhaps the following is best for your situation:
[pre]link together the more stable parts of your system.  That way,
you can keep the source seperate but still gather up some of the .o's
into a more conglamorative one).

- Greg
-- 
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
 ***WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
Technical Details
Message-ID: <59uska$cu5@panix.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <gnusenetraub-2412960039190001@dialup52.afn.org>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,157ed6c64d1aa006
X-Google-Attributes: gid11318c,public
X-Google-Thread: 101ec9,8f16387167a7efa5
X-Google-Attributes: gid101ec9,public
X-Google-Thread: ffc26,8f16387167a7efa5
X-Google-Attributes: gidffc26,public
X-Google-Thread: fc89c,8f16387167a7efa5
X-Google-Attributes: gidfc89c,public
X-Google-Thread: 105df1,8f16387167a7efa5
X-Google-Attributes: gid105df1,public
X-Google-Thread: 1014db,8f16387167a7efa5
X-Google-Attributes: gid1014db,public
From: comeau@panix.com (Greg Comeau)
Subject: Re: #ifndef/#ifdef problems in my header file (conditional header inclusion)
Date: 1996/12/26
Message-ID: <59uska$cu5@panix.com>
X-Deja-AN: 206091952
references: <gnusenetraub-2412960039190001@dialup52.afn.org>
organization: Comeau Computing
reply-to: comeau@csanta.attmail.com
newsgroups: comp.unix.programmer,gnu.gcc.help,comp.lang.c,comp.sys.mac.programmer.help,comp.os.ms-windows.programmer.misc,comp.sys.amiga.programmer