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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Idempotent header file proposal
  5. Message-ID: <1992Nov20.010009.24900@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Nov19.090742.23696@cbfsb.cb.att.com>
  8. Date: Fri, 20 Nov 1992 01:00:09 GMT
  9. Lines: 48
  10.  
  11. nh@cbnewsg.cb.att.com (nicholas.hounsome) writes:
  12.  
  13. >Can we not have a standard pragma to say that a header file is idempotent
  14. >(A long word  I discovered that means that it only need be included once).
  15.  
  16. Not quite.  It means that (in this context) multiple inclusions have
  17. the same effect as one inclusion.
  18.  
  19. >eg. put #pragma IDEMPOTENT in the header and have the preprocessor
  20. >understand that it need not bother reading this file again it seems
  21. >very easy to implement provided only that you use an ANSI preprocessor
  22. >and it requires no language extension since it is only a convention
  23. >which the preprocessor can ignore if it does not understand it.
  24.  
  25. Some compilers have this feature, often called "#pragma once".
  26.  
  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. For example, the compiler could have the contents of the standard
  37. headers already available in its symbol table but inactive when
  38. the compiler starts up.  It would activate the definitions
  39. associated with a standard header when the include directive was seen.
  40. This takes no time, and has no penalty if done more than once.
  41.  
  42. One problem with pragmas is that they are not necessarily harmless
  43. when not implemented on another compiler.  My favorite example, for
  44. which I cannot take credit, involves "#pragma once".  As I noted
  45. earlier, on some compilers it means "ignore further requests to
  46. include this header."  On another compiler, it might mean "turn
  47. on Customer Engineer features."  These features are turned off
  48. with "#pragma offce".
  49.  
  50. Many people involved with standards efforts believe that there should
  51. not be such a thing as a "standard pragma".  A pragma by its nature
  52. controls something non-standard, non-portable, or system-specific.
  53. If the thing controlled were generally portable, it should probably
  54. be a language feature, not a pragma.
  55. -- 
  56.  
  57. Steve Clamage, TauMetric Corp, steve@taumet.com
  58. Vice Chair, ANSI C++ Committee, X3J16
  59.