home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: Re: Multiple Header Files Problem
- Message-ID: <rmartin.721442494@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <720993360snx@trmphrst.demon.co.uk> <rmartin.721359424@thor> <1992Nov10.104447.12882@us-es.sel.de>
- Date: Wed, 11 Nov 1992 00:41:34 GMT
- Lines: 57
-
- reindorf@us-es.sel.de (Charles Reindorf) writes:
-
- |In article <rmartin.721359424@thor>, rmartin@thor.Rational.COM (Bob Martin) writes:
- ||> A more interesting variation on this issue is the problem of "circular
- ||>
- ||> [ etc.]
-
- |It is usual, in header files, to structure them so :
-
-
- || # ifndef <HeaderFileName>_h
- || # define <HeaderFileName>_h
- ||
- ||
- || ... body of include file ...
- ||
- ||
- || # endif
-
- |This prevents cyclic dependencies and has been in common practice for, well, ages.
-
- Of course! And of course I use this technique myself, and instruct my
- students to do the same.
-
- What I had not realized, until you (and many others) pointed it out to
- me, is that the #ifndef convention breaks inclusion cycles. Of course
- it does.
-
- I have run into inclusion cycles several times in the past few years.
- The first one I ran into, was of my own creation. This was before I
- knew about the #ifndef convention. I discovered that convention at a
- separate time, and used it to solve a different problem. So the two
- never gelled together in my brain. The other cycles I have stumbled
- accross were written by clients of mine who were just starting at C++,
- and had not yet learned all the conventions.
-
- However, using the #ifndef convention does not solve all the problems
- related to inclusion, nor obviate the need to make judicious use of
- forward declarations. #ifndef, while it *does* keep the contents of a
- header file from being compiled more than once, does not keep the
- header file from being *read* more than once. Thus, if care is not
- taken, compile times can grow quite long.
-
- Moreover, some compilers limit the number of files that they will
- include, or at least the depth of the inclusions.
-
- So, take care when using #include in a header file. Always be sure
- that you the #include is necessary, and that it cannot be replaced
- with a forward declaration.
-
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-