Include files that depend on include files

Robert Watson rwatson at FreeBSD.org
Wed Aug 10 00:38:13 GMT 2005


On Wed, 10 Aug 2005, Dirk GOUDERS wrote:

> > This is intentational.  We try to avoid having headers bring in more 
> > then absolutly required when included.  I'm not sure what your second 
> > question means.
>
> With my second question I wanted to ask if this intention is only for 
> kernel level code or a general one.  I am asking this, because somewhen 
> in a project that I was not actually participating in I heard or read a 
> rule that roughly said: "all include files have to include all files 
> they depend on and compile cleanly", but that project was on a user 
> space program.

In general, in the role the operating system vendor, it's important to 
minimize "header pollution" as much as possible.  Unlike C++, C doesn't 
have a notion of structured use of the name space, and if things are 
massively nested included, that dramatically increases the chance of a 
conflict of use between "the system" and a user application.  You'll 
notice that increasingly, FreeBSD-specific defines are prefixed with '_', 
as that indicates use of reserved "you're the system" symbol space.  For 
example, the "#ifdef KERNEL"'s all over the place became "#ifdef _KERNEL", 
as there's no reason an application shouldn't use a define named KERNEL.

The rules are a bit different if you're the application, although it's in 
your interest to include as a few unnecessary headers as possible, to 
reduce the chances of getting definitions that conflict with your 
application.

Robert N M Watson



More information about the freebsd-hackers mailing list