Where Should I Put Header Calls When Using Multiple Files?
Suppose I am working on a program with 3 files:
- Main.c (main file which runs the program)
- Functions.c (collection of functions used by main.c)
- MyHeader.h (list of function prototypes, global variables, typedefs and what not)
Suppose also that I need to use both the stdio.h and stdlib.h libraries in this program.
I am used to put only a #include "MyHeader.h" on both main.c and functions.c, and then put #include <stdio.h> and #include <stdlib.h> on MyHeader.h (this seems to me the most logic and not-redundant solution).
But, I have seen some very experienced programmers put no #includes at all on MyHeader.h, and then put them as needed on main.c and functions.c, so in this example MyHeader.h would have no #includes, main.c would have:
#include <stdio.h>
#include "MyHeader.h"
and functions.c would have:
#include <stdio.h>
#include <stdlib.h>
#include "MyHeader.h"
As you can see with this second method stdio.h is included twice, while with my method only once.
So which is the best/recommended way to call headers (if there is one)?