Recursive #includes

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Feb 26 15:54:03 AEST 1989


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

That is a good, commonly used scheme.

>I suspect that it will also encourage the inclusion of files that are
>not even needed ...

That hasn't been my experience.

>Furthermore, permitting recursive includes may tend to smear the
>separation between modular components of the software system, and
>designing a correct makefile will be a mess.

If a module's interface depends on another's, then necessarily you
have to #include the other module's interface definition just to
properly declare this one's.  Of course most modules (packages)
should not have interfaces that are tied to others, but sometimes
it is necessary.

It's easy to get the Makefile correct; just declare that a header
depends on the others that it #includes.

>These problems, together with the discovery that some preprocessors
>consider any recursive include to be a fatal error, have motivated me
>to discontinue the use of this trick, and discontinue the use of
>recursive includes as well.

Any such preprocessor is badly broken.  K&R 1st Edition imposes no
such constraint.  How about telling us what brands of compiler have
this problem, so we can avoid purchasing them?



More information about the Comp.lang.c mailing list