If it's a BIG project, you almost certainly HAVE to have multiple headerfiles to make anything sensible out of your project.
I have worked on projects that have several thousand source files, and many hundred header files, totalling millions of lines. You couldn't put all those headerfiles together into one file, and do any meaningful work.
A headerfile should provide one "funcionality". So, if you have a program dealing with customer accounts, stock, invoices, and such, you may have one "customer.h", a "stock.h" and a "invoice.h". You'll probably also have a "dateutils.h" for calculating the "when does this invoice need to be paid by, and how long is it since the invoice was sent out, to send out reminders.
In general, keeping headerfiles SMALL is a good thing. If one headerfile needs something from another one, have it include that.
Of course, if a function is not used outside a particular file, it should not go in a headerfile, and to avoid "leaking names", it should be static
. E.g:
static void func(int x)
{
return x * 2;
}
If, for some reason, you need to forward declare func
(because some function before func
needs to call func
), then declare it at the beginning of the source file. There is no need to "spread it around" by adding it to a header file.
By marking it static
, you are making it clear that "nobody else, outside this file, uses this function". If at a later stage, you find that "Hmm, this func
is really useful in module B as well", then add it to a suitable header file (or make a new header file), and remove the static
. Now, anyone reading the source file knows that they will need to check outside of this source file to make sure that any changes to func
are OK in the rest of the code.