home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Idempotent header file proposal
- Message-ID: <1992Nov20.010009.24900@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Nov19.090742.23696@cbfsb.cb.att.com>
- Date: Fri, 20 Nov 1992 01:00:09 GMT
- Lines: 48
-
- nh@cbnewsg.cb.att.com (nicholas.hounsome) writes:
-
- >Can we not have a standard pragma to say that a header file is idempotent
- >(A long word I discovered that means that it only need be included once).
-
- Not quite. It means that (in this context) multiple inclusions have
- the same effect as one inclusion.
-
- >eg. put #pragma IDEMPOTENT in the header and have the preprocessor
- >understand that it need not bother reading this file again it seems
- >very easy to implement provided only that you use an ANSI preprocessor
- >and it requires no language extension since it is only a convention
- >which the preprocessor can ignore if it does not understand it.
-
- Some compilers have this feature, often called "#pragma once".
-
- This solves a problem outside the language, and for that reason is
- probably not appropriate to put in the language Standard. In
- particular, you are assuming that a standard header is a file, and
- that it is read and processed by the compiler in the way user text
- files are processed. Nothing in the language specification requires
- this to be the case. Any compiler is free to recognize the names of
- the standard headers and do any kind of magic, so long as the net
- result is what the Standard specifies.
-
- For example, the compiler could have the contents of the standard
- headers already available in its symbol table but inactive when
- the compiler starts up. It would activate the definitions
- associated with a standard header when the include directive was seen.
- This takes no time, and has no penalty if done more than once.
-
- One problem with pragmas is that they are not necessarily harmless
- when not implemented on another compiler. My favorite example, for
- which I cannot take credit, involves "#pragma once". As I noted
- earlier, on some compilers it means "ignore further requests to
- include this header." On another compiler, it might mean "turn
- on Customer Engineer features." These features are turned off
- with "#pragma offce".
-
- Many people involved with standards efforts believe that there should
- not be such a thing as a "standard pragma". A pragma by its nature
- controls something non-standard, non-portable, or system-specific.
- If the thing controlled were generally portable, it should probably
- be a language feature, not a pragma.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-