home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16625 < prev    next >
Encoding:
Text File  |  1992-11-20  |  3.9 KB  |  92 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!linac!att!cbnewsk!cbnewsj!att-out!cbfsb!cbnewsg.cb.att.com!nh
  3. From: nh@cbnewsg.cb.att.com (nicholas.hounsome)
  4. Subject: Re: Idempotent header file proposal
  5. Message-ID: <1992Nov20.103616.19956@cbfsb.cb.att.com>
  6. Sender: news@cbfsb.cb.att.com
  7. Organization: AT&T
  8. References: <1992Nov20.010009.24900@taumet.com>
  9. Date: Fri, 20 Nov 1992 10:36:16 GMT
  10. Lines: 80
  11.  
  12. From article <1992Nov20.010009.24900@taumet.com>, by steve@taumet.com (Steve Clamage):
  13. > nh@cbnewsg.cb.att.com (nicholas.hounsome) writes:
  14. >>Can we not have a standard pragma to say that a header file is idempotent
  15. >>(A long word  I discovered that means that it only need be included once).
  16. > Not quite.  It means that (in this context) multiple inclusions have
  17. > the same effect as one inclusion.
  18.  
  19. I think that what I said means the same thing
  20.  
  21. >>eg. put #pragma IDEMPOTENT in the header and have the preprocessor
  22. >>understand that it need not bother reading this file again it seems
  23. >>very easy to implement provided only that you use an ANSI preprocessor
  24. >>and it requires no language extension since it is only a convention
  25. >>which the preprocessor can ignore if it does not understand it.
  26. > Some compilers have this feature, often called "#pragma once".
  27. > This solves a problem outside the language, and for that reason is
  28. > probably not appropriate to put in the language Standard.  In
  29. > particular, you are assuming that a standard header is a file, and
  30. > that it is read and processed by the compiler in the way user text
  31. > files are processed.  Nothing in the language specification requires
  32. > this to be the case.  Any compiler is free to recognize the names of
  33. > the standard headers and do any kind of magic, so long as the net
  34. > result is what the Standard specifies.
  35.  
  36. The "standard" headers are not too much of a problem it is 
  37. headers from large libraries such as GUIs and user headers that
  38. make up the bulk.
  39.  
  40. > For example, the compiler could have the contents of the standard
  41. > headers already available in its symbol table but inactive when
  42. > the compiler starts up.  It would activate the definitions
  43. > associated with a standard header when the include directive was seen.
  44. > This takes no time, and has no penalty if done more than once.
  45. > One problem with pragmas is that they are not necessarily harmless
  46. > when not implemented on another compiler.  My favorite example, for
  47. > which I cannot take credit, involves "#pragma once".  As I noted
  48. > earlier, on some compilers it means "ignore further requests to
  49. > include this header."  On another compiler, it might mean "turn
  50. > on Customer Engineer features."  These features are turned off
  51. > with "#pragma offce".
  52. > Many people involved with standards efforts believe that there should
  53. > not be such a thing as a "standard pragma".  A pragma by its nature
  54. > controls something non-standard, non-portable, or system-specific.
  55. > If the thing controlled were generally portable, it should probably
  56. > be a language feature, not a pragma.
  57. > -- 
  58.  
  59. Point taken.
  60.  
  61. The reason that I suggested a pragma was to minimize impact on existing code.
  62.  
  63. I could have suggested changing the semantics of #include but I know that
  64. this would break the 0.0001% of code that intentionaly includes headers
  65. multiple times.
  66.  
  67. How about a different form for #include such as say #use with the
  68. corresponding meaning?
  69.  
  70. > Steve Clamage, TauMetric Corp, steve@taumet.com
  71. > Vice Chair, ANSI C++ Committee, X3J16
  72.  
  73. Others have pointed out that some compilers notice when header code is
  74. wrapped in #ifdef HEADER1_H but this seems messy to me and I consider
  75. readability to be a major issue.
  76.  
  77. Also for those people who say that nothing should be done because it isn't a 
  78. language problem or can be worked around I would point out that this
  79. applies equaly to everything that the preprocessor does. The object is
  80. to get maintainable programs produced as fast as possible.
  81.  
  82. Nick Hounsome
  83. AT&T Network Systems UK
  84.