Article View: comp.unix.programmer
Article #3651Re: #ifndef/#ifdef problems in my header file (conditional header inclusion)
From: Greg Comeau
Date: Fri, 27 Dec 1996 00:00
Date: Fri, 27 Dec 1996 00:00
51 lines
2923 bytes
2923 bytes
In article <0a05qnw60.alamito@marketgraph.xs4all.nl> rvg@marketgraph.xs4all.nl writes:
>In <gnusenetraub-2412960039190001@dialup52.afn.org> Mauricio Tavares
><raub@kushana.aero.ufl.edu> wrote:
>
>> 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
>
>Something somewhere is wrong. Having includes be included multiple times this
>way would also mean that any #define's in the include file would be
>forgotten. That will certainly NOT be the case.
>Other possibility: #ifndef is broke.
Nothing is broke, or wrong. In the original post, the author was
expecting the ifndef (and other things) to live _across_ translation units
(.c files if you will) not the typical scenario of a .c that included a .h
which may or may not have already #include'd the same thing.
>Better: try #include-ing such a file, then do:
>#ifdef MOOSE
>#error Should get here
>#else
>#error What is going on here?
>#endif
>
>in your C/C++ source.
>
>Let me/us know the results.
As per above, this is not relevant to the "problem"
This is a good technique for people to know in general though.
- 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:
<5a1dmk$ska@panix.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<gnusenetraub-2412960039190001@dialup52.afn.org> <0a05qnw60.alamito@marketgraph.xs4all.nl>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: 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 X-Google-Thread: ffc26,8f16387167a7efa5 X-Google-Attributes: gidffc26,public From: comeau@panix.com (Greg Comeau) Subject: Re: #ifndef/#ifdef problems in my header file (conditional header inclusion) Date: 1996/12/27 Message-ID: <5a1dmk$ska@panix.com> X-Deja-AN: 206268148 references: <gnusenetraub-2412960039190001@dialup52.afn.org> <0a05qnw60.alamito@marketgraph.xs4all.nl> 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