Programming Style
Tim W Smith
ts at cup.portal.com
Thu Apr 18 17:31:05 AEST 1991
I try to follow two rules with my include files:
1. An include file shall not cause harm by being
included multiple times.
2. An include file shall include all other include
files needed to make it work, unless that conflicts
with the first rules.
Rule #2 means that if you want, say, the structure definition
for a user area, you say
#include <sys/user.h>
You do NOT have to say:
#include <sys/types.h>
#include <sys/param.h>
#include <sys/config.h>
#include <sys/proc.h>
#include <sys/dir.h>
#include <sys/mmu.h>
#include <sys/buf.h>
#include <sys/user.h>
Sometimes this can get ugly, though.
I had a pair of include files that happened to need parts of
each other. What needed to happen at compile time was that
the compiler should see the first part of file A, then file B, and
then the rest of file A.
Each file ended up including the other, with appropriate
conditionals to make sure the right thing happened, but it
was not pretty.
Tim Smith
More information about the Comp.lang.c
mailing list