home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!news.tek.com!uw-beaver!news.u.washington.edu!news.uoregon.edu!cs.uoregon.edu!sgiblab!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!hellgate.utah.edu!fcom.cc.utah.edu!swillden
- From: swillden@news.ccutah.edu (Shawn Willden)
- Subject: Re: Multiple Header Files Problem
- Message-ID: <1992Nov11.015747.20842@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Reply-To: swillden@icarus.weber.edu
- Organization: University of Utah Computer Center
- X-Newsreader: Tin 1.1 PL3
- References: <rmartin.721442494@thor>
- Date: Wed, 11 Nov 92 01:57:47 GMT
- Lines: 55
-
- rmartin@thor.Rational.COM (Bob Martin) writes:
- : 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
- : |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.
- :
- : 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.
-
- While I agree with that it is a good idea to choose your #included
- files carefully, the above-metioned problems are also easily avoided
- by simply wrapping each inclusion in its own #ifndef...#endif pair.
- Like:
-
- #ifndef SOMEFILE_H
- #include "somefile.h"
- #endif
-
- That way, if somefile.h has already been included once, the compiler
- won't even have to read it again. If this technique is always used
- the #ifndef..#endif pairs are not even needed in the included file,
- though I always use them, just in case someone else makes a mistake
- (something I'm sure *I* would never do :-)
-
- : --
- : 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++
-
- --
- Shawn Willden
- swillden@icarus.weber.edu
-