home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16406 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.0 KB  |  55 lines

  1. Newsgroups: comp.lang.c
  2. 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
  3. From: pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl)
  4. Subject: Re: Please help me with my #include mess-up.
  5. Message-ID: <pal.721574512@regent.e-technik.tu-muenchen.de>
  6. Sender: news@regent.e-technik.tu-muenchen.de (News System)
  7. Organization: Technical University of Munich, Germany
  8. References: <1992Nov11.172840.5540@news.ysu.edu>
  9. Date: Thu, 12 Nov 1992 13:21:52 GMT
  10. Lines: 43
  11.  
  12. ae007@yfn.ysu.edu (Daniel Newcombe) writes:
  13.  
  14. >Well here is my problem:  I have these modules:
  15. >  MOSTYPES.H - defines several types I am using in this
  16. >    project, such as boolean, and a few structs and typedefs
  17. >QUEUE.H - the header file for my queue class which has a few
  18. >   inline things in it.
  19. >   This has to include mostypes.h because it needs boolean.
  20. >QUEUE.CPP - the rest of the code for the queues.  It includes
  21. >  queue.h
  22. >MAINMOD.CPP - my main module.  It includes QUEUE.H and MOSTYPES.H.
  23. >When I compile I get a whole mess of errors saying that all sorts
  24. >of things in MOSTYPES.H are redefined.  There are a lot more        
  25. >modules that are going to have to use mostypes.h before it's   
  26. >all over with.
  27.  
  28. >My question - how do I get this to compile, while still keeping
  29. >the code portable and re-usable???
  30.  
  31. Hi!
  32.  
  33. 1. include ONLY these headers, that are obviously needed in a source.
  34.    Do NOT rely that a specific header is included somewhere else.
  35.    Write your headers that way, that you are independed from the
  36.    arragement of your includes in the source.
  37.  
  38. 2. You can get this by using a construciton like this (for queue.h):
  39.  
  40. #ifndef __QUEUE_H
  41. #define __QUEUE_H
  42.  
  43. #include "mostype.h"
  44.  
  45. /* definitions, macros, etc */
  46.  
  47. #endif  /* EOF */
  48.  
  49. Do the same thing for each header you use. This will include this
  50. header file ONLY, if it has not been included before. This way you also
  51. prevent possible include-loops.
  52.  
  53. Peter Loibl
  54. pal@regent.e-technik.tu-muenchen.de
  55.