Path: utzoo!attcan!uunet!husc6!purdue!gatech!ulysses!gsf From: gsf@ulysses.homer.nj.att.com (Glenn Fowler[eww]) Newsgroups: comp.lang.c++ Subject: Re: Managing C/C++ Libraries: Dependencies Summary: #include_once != #ifndef ... Message-ID: <10853@ulysses.homer.nj.att.com> Date: 14 Nov 88 15:54:30 GMT References: <8387@nlm-mcs.arpa> <3414@geaclib.UUCP> Organization: AT&T Bell Laboratories, Murray Hill Lines: 49 In article <3414@geaclib.UUCP>, dave@lethe.UUCP (David Collier-Brown) writes: > > In article <124300001@inmet> stt@inmet writes: > >>A simple language extension would be: > >> > >>#include_once "classname.h" > [definition of include_once as equivalent to > #ifdef classname_h > # include "classname.h" > # define classname_h > #endif > ] #include_once is fundamentally different from #ifndef...#endif: #include_once idempotency controlled by includer #ifndef... idempotency controlled by includee an include file intended to be included more than once is usually written as such, so #include_once seems to be placing the control in the wrong place from an efficiency viewpoint, though, #include_once may be a win since the include file contents need not be scanned taking this into account, an experimental preprocessor, used by some internal development organizations, has been doing the following for the past year with no problems (other than stretching the dpANSI C #include ``implementation defined'' meaning): (1) by default each #include file is included only once (2) a run time option forces the old behavior (3) a file to be included more than once must contain the statement ``#pragma pp:multiple'' that is evaluated during the first include comments: (1) how are files identified? does "x" == , does "./x" == "x", with symlinks and ``ln -s a b'', does "a" == "b" (note that is not a valid identity check on some distributed file system implementations) (3) pick your favorite #pragma syntax this mechanism allows one to write headers in a dpANSI C comforming manner while still exploiting efficient pp implementations: (a) idempotent include files are wrapped with #ifndef...#endif (b) multiply included headers contain ``#pragma pp:multiple'' -- Glenn Fowler (201)-582-2195 AT&T Bell Laboratories, Murray Hill, NJ uucp: {att,decvax,ucbvax}!ulysses!gsf internet: gsf@ulysses.att.com