Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!usc!orion.oac.uci.edu!uci-ics!rfg From: rfg@ics.uci.edu (Ron Guilmette) Newsgroups: comp.lang.c++ Subject: #pragma once (was Re: A solution to the multiple inclusion problem) Keywords: #include c c++ inclusion Message-ID: <1989Oct27.163755.12976@paris.ics.uci.edu> Date: 27 Oct 89 23:37:55 GMT References: <14240@well.UUCP> <2082@plx.UUCP> Reply-To: Ron Guilmette Organization: University of California, Irvine - Dept of ICS Lines: 39 In article <2082@plx.UUCP> johnc@plx.UUCP (John C.) writes: > >b) Regarding modifications to the semantics of #include (so the compiler >would keep track of which file names had already been scanned), you >might be interested to know that MetaWare's compilers have had a >"conditional include" (C_Include) directive for several years now, >which does exactly this. Perhaps the preferred language change, if >any, is to define such a "conditional-include" directive, perhaps >"#cond_include" or "#c_include". [How about it, Dr. Stroustrup?] Think about what you are saying. If a given include file should (or must) only be included once, then that fact is a property of the include file itself, and not a property of any file which may include it. That is why the GNU C and C++ compilers have implemented the #pragma once construct, which can be placed in a given include file to signify (to the compiler) that the given file should only be included once (during a given compilation) regardless of the number of include "requests" for the given file. By the way, I have been sitting here reading numerous items about this stale old problem (multiple inclusions) and I have noticed that every scheme that has been proposed here recently has one or more of the following major deficiencies: * It is no more efficient than normal multiple inclusion (given ANSI C's rules regarding the tokenization of material inside of #if-#endif pairs). * It directly violates ANSI C semantics. * It is not implemented (i.e. just a pipe-dream). Mind you, the #pragma once construct probably has deficiency #2, but I think that it tiptoes around the rules rather than trying to overtly overthrow them. // rfg