Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!aplcen!haven!uvaarpa!mcnc!rti!sunpix!matthew From: matthew@sunpix.UUCP ( Sun Visualization Products) Newsgroups: comp.lang.c Subject: Re: A solution to the multiple inclusion problem Keywords: #include c c++ Message-ID: <946@friar-taac.UUCP> Date: 24 Oct 89 13:46:46 GMT References: <14240@well.UUCP> <15316@bloom-beacon.MIT.EDU> Reply-To: matthew@friar-taac.UUCP (Matthew Stier - Sun Visualization Products) Distribution: comp Organization: Sun Microsystems, RTP, NC Lines: 70 In article <15316@bloom-beacon.MIT.EDU> tada@athena.mit.edu (Michael J Zehr) writes: |In article <14240@well.UUCP> nagle@well.UUCP (John Nagle) writes: |>[problem of multiple exclusion, generally solved by:] |> #ifndef XXX |> #define XXX |> ...content... |> #endif |>This works, but on the second inclusion, the file still has to be read and |>parsed, at least by the level of processing that reads "#" statements. |>[slowing compilation, particularly in C++ programs] | |>[proposed compiler optimization binding the 'XXX' defined above to the |>included file and not including it a second time.] | |there's another solution you can manage without having to get your |compiler vendor to make such an extension: | | |#ifndef FOO |#define FOO |#include "foo_real.h" |#endif | |admittedly there's an extra file open for the first time reading |through, and you still have to open files when #including the second |time, but it's not as bad as having to read the entire file in |(particularly if you have some really *large* files). library files |could be changed to this with relatively little effort and no compiler |changes, and users' header files for large systems could be changed to |work faster *today* without having to wait for the vendors to decide to |do this. | |(unless i'm missing something obvious and being really stupid this |works....) | |-michael j zehr or if your sure all your header files use the: #ifndef XXX #define XXX ...content... #endif constructs, you could just alter you source code a bit, and do an '#ifndef', '#endif' around each '#include'. This would require adding two lines for each included file, and no extra files open. /* * Start of source code */ #ifndef STDIO.H #include #endif #ifndef CTYPE.H #include #endif Now, if only library writers used the '#ifndef', '#endif' construct consistantly. -- Matthew Lee Stier | Sun Microsystems --- RTP, NC 27709-3447 | "Wisconsin Escapee" uucp: sun!mstier or mcnc!rti!sunpix!matthew | phone: (919) 469-8300 fax: (919) 460-8355 |