Path: utzoo!attcan!uunet!actnyc!prh From: prh@actnyc.UUCP (Paul R. Haas) Newsgroups: comp.lang.c++ Subject: Re: Including header files minimally. Message-ID: <1073@actnyc.UUCP> Date: 21 Nov 88 20:05:55 GMT References: <3561@pt.cs.cmu.edu> <7860@nsc.nsc.com> <3614@pt.cs.cmu.edu> <10873@ulysses.homer.nj.att.com> Reply-To: prh@actnyc.UUCP (Paul R. Haas) Organization: InterACT Corporation Lines: 40 In article <10873@ulysses.homer.nj.att.com> gsf@ulysses.homer.nj.att.com (Glenn Fowler[eww]) writes: >In article <3614@pt.cs.cmu.edu>, dld@f.gp.cs.cmu.edu (David Detlefs) writes: >> ... >> [David discusses his scheme for avoiding including files to often.] >> ... > > [Glenn shows a flaw with David's method.] I think I have a solution which is ANSI compatible and requires minimal source code changes (some people write their header files this way already). Make the C preprocessor recognize files of the form: comments and whitespace #ifndef SOME_SYMBOL any properly nested stuff, hopefully including "#define SOME_SYMBOL" #end comments and whitespace And only include them a second time if the symbol is not defined. The preprocessor would have to keep a table of include file names and symbols that they depend on. Obviously, this should be turned off if the preprocessor is sending comments through. Advantages: o Code will behave the same way with preprocessors without this feature. o No #pragmas required o Easy to explain to people Disadvantages: o In order for this to speed things up, most header files should be written in a particular form. o I am not sure how much effort this will take. It looks like I will end up putting some ugly hacks into cccp.c. o Will slightly slow down the preprocessor for header files which lack the #ifndef ... #endif structure. Feel free to point out something that I missed. I am going to look into adding this to the Gnu preprocessor, cccp. If anyone else is doing something similar, let me know. ----- Paul Haas uunet!actnyc!prh or prh@frith.egr.msu.edu (212) 696-3653