A solution to the multiple inclusion problem
Michael J Zehr
tada at athena.mit.edu
Tue Oct 24 04:04:19 AEST 1989
In article <14240 at well.UUCP> nagle at 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:
<foo.h:>
#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
More information about the Comp.lang.c
mailing list