prev up next   top/contents search

comp.lang.c FAQ list · Question 10.7

Q: Is it acceptable for one header file to #include another?

A: It's a question of style, and thus receives considerable debate. Many people believe that ``nested #include files'' are to be avoided: the prestigious Indian Hill Style Guide (see question 17.9) disparages them; they can make it harder to find relevant definitions; they can lead to multiple-definition errors if a file is #included twice; they can lead to increased compilation time; and they make manual Makefile maintenance very difficult. On the other hand, they make it possible to use header files in a modular way (a header file can #include what it needs itself, rather than requiring each #includer to do so); a tool like grep (or a tags file) makes it easy to find definitions no matter where they are; a popular trick along the lines of:

	...header file contents...
(where a different bracketing macro name is used for each header file) makes a header file ``idempotent'' so that it can safely be #included multiple times; a clever compiler can avoid expending any more time on later instances of an already-included header; and automated Makefile maintenance tools (which are a virtual necessity in large projects anyway; see question 18.1) handle dependency generation in the face of nested #include files easily. See also question 17.10.

References: Rationale Sec. 4.1.2

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North