home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!sun-barr!cs.utexas.edu!swrinde!emory!europa.asd.contel.com!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!math.fu-berlin.de!informatik.tu-muenchen.de!regent!pal
- From: pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl)
- Subject: Re: Please help me with my #include mess-up.
- Message-ID: <pal.721574512@regent.e-technik.tu-muenchen.de>
- Sender: news@regent.e-technik.tu-muenchen.de (News System)
- Organization: Technical University of Munich, Germany
- References: <1992Nov11.172840.5540@news.ysu.edu>
- Date: Thu, 12 Nov 1992 13:21:52 GMT
- Lines: 43
-
- ae007@yfn.ysu.edu (Daniel Newcombe) writes:
-
- >Well here is my problem: I have these modules:
- > MOSTYPES.H - defines several types I am using in this
- > project, such as boolean, and a few structs and typedefs
- >QUEUE.H - the header file for my queue class which has a few
- > inline things in it.
- > This has to include mostypes.h because it needs boolean.
- >QUEUE.CPP - the rest of the code for the queues. It includes
- > queue.h
- >MAINMOD.CPP - my main module. It includes QUEUE.H and MOSTYPES.H.
- >When I compile I get a whole mess of errors saying that all sorts
- >of things in MOSTYPES.H are redefined. There are a lot more
- >modules that are going to have to use mostypes.h before it's
- >all over with.
-
- >My question - how do I get this to compile, while still keeping
- >the code portable and re-usable???
-
- Hi!
-
- 1. include ONLY these headers, that are obviously needed in a source.
- Do NOT rely that a specific header is included somewhere else.
- Write your headers that way, that you are independed from the
- arragement of your includes in the source.
-
- 2. You can get this by using a construciton like this (for queue.h):
-
- #ifndef __QUEUE_H
- #define __QUEUE_H
-
- #include "mostype.h"
-
- /* definitions, macros, etc */
-
- #endif /* EOF */
-
- Do the same thing for each header you use. This will include this
- header file ONLY, if it has not been included before. This way you also
- prevent possible include-loops.
-
- Peter Loibl
- pal@regent.e-technik.tu-muenchen.de
-