Recursive #includes
Dominick Samperi
samperi at marob.MASA.COM
Sun Feb 26 12:37:38 AEST 1989
Are recursive #includes hazardous to your software's health?
I'm working on a system where each header file has the form:
<contents of foo.h>:
#ifndef H_FOO
#define H_FOO
defines, declarations, etc.
#endif
This scheme permits header files to be included two or more times, even
recursively, where the second and subsequent includes of the same file
will have no effect. (That is, a header file A can include another header
file B, which in turn includes A, but since H_A will be defined when A
is included the first time, the second include of A will have no effect,
and the recursion will end.)
Although this trick will avoid the common problems caused by including
a header file more than once, I suspect that it will also encourage
the inclusion of files that are not even needed (since there is
no chance for multiple definitions, if there is some chance that the
definitions may be needed, what the heck). 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.
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.
Perhaps others could comment on this.
--
Dominick Samperi -- ESCC
samperi at marob.masa.com
uunet!hombre!samperi
More information about the Comp.lang.c
mailing list