Recursive #includes

Stacey Campbell stacey at hcr.UUCP
Fri Mar 3 07:50:02 AEST 1989


In article <570 at marob.MASA.COM> samperi at marob.UUCP writes:
>#ifndef H_FOO
>#define H_FOO
>
>defines, declarations, etc.
>
>#endif

It is almost essential on very large projects to implement a
form of guarding of recursive includes.  I'm currently working
on a project where a typical 'crunched' cpp file is over 10000
lines and where over 100 included files are nested up to 14 levels.
The guarding is implemented differently;

(contents of bar.h)

#ifndef FOO
#include <foo.h>
#endif

(contents of foo.h)

#ifndef FOO
#define FOO
...
#endif

Yes, two sets of guards just in case someone implements a
module including foo.h without checking FOO.  Prechecking
to see if a module has already been included saves an
enormous amount of compile time and file inclusion overhead.
-- 
Stacey Campbell, HCR Corporation, {lsuc,utzoo,utcsri}!hcr!stacey



More information about the Comp.lang.c mailing list