Check out the C and C++ coding standards at the NASA Goddard Space Flight Center. The one rule that I specially noted in the C standard and have adopted in my own code is the one that enforces the 'standalone' nature of header files. In the implementation file xxx.cpp for the header xxx.h, ensure that xxx.h is the first header included. If the header is not self-contained at any time, then compilation will fail. It is a beautifully simple and effective rule.
The only time it fails you is if you port between machines, and the xxx.h header includes, say, <pqr.h>
, but <pqr.h>
requires facilities that happen to be made available by a header <abc.h>
on the original platform (so <pqr.h>
includes <abc.h>
), but the facilities are not made available by <abc.h>
on the other platform (they are in def.h
instead, but <pqr.h>
does not include <def.h>
). This isn't a fault of the rule, and the problem is more easily diagnosed and fixed if you follow the rule.