Alex Rivera | Logout

Your preferred C/C++ header policy for big projects?

Asked 2008-10-08T09:19:12.737
52

When working on a big C/C++ project, do you have some specific rules regarding the #include within source or header files?

For instance, we can imagine to follow one of these two excessive rules:

  1. #include are forbidden in .h files; it is up to each .c file to include all the headers it needs
  2. Each .h file should include all its dependancies, i.e. it should be able to compile alone without any error.

I suppose there is trade-off in between for any project, but what is yours? Do you have more specific rules? Or any link that argues for any of the solutions?

Edit
Report

1 Answer

5
  1. Always have some sort of header guard.
  2. Do not pollute the user's global namespace by putting any using namespace statements in a header.
answered 2008-10-08T11:36:37.530

Your Answer