- #1
Eus
- 94
- 0
Hi Ho!
I often heard people say that we should avoid multiple inclusion of a header file.
And, they very often show how to do it.
But, I myself haven't yet found the reason of not to do it when certain precautions are taken.
What I am going to discuss here is C programming, not C++.
I included one single header file containing:
- function prototype
- struct declaration
- enum declaration
- typedef
multiple times in several source code files, but my gcc happily compiled the source code files.
Of course, if I added one variable definition within the header file (e.g. int x = 0), gcc complained of multiple variable declarations.
But, I know that a variable should be best defined in a source code file not in a header file.
Therefore, as far as I don't put any variable definition in a header file, there is no problem with the multiple inclusion of the header file, isn't there?
Is there any reason to say that multiple inclusion of a header file should be avoided at all?
What do you think?
Thank you.
Eus
I often heard people say that we should avoid multiple inclusion of a header file.
And, they very often show how to do it.
But, I myself haven't yet found the reason of not to do it when certain precautions are taken.
What I am going to discuss here is C programming, not C++.
I included one single header file containing:
- function prototype
- struct declaration
- enum declaration
- typedef
multiple times in several source code files, but my gcc happily compiled the source code files.
Of course, if I added one variable definition within the header file (e.g. int x = 0), gcc complained of multiple variable declarations.
But, I know that a variable should be best defined in a source code file not in a header file.
Therefore, as far as I don't put any variable definition in a header file, there is no problem with the multiple inclusion of the header file, isn't there?
Is there any reason to say that multiple inclusion of a header file should be avoided at all?
What do you think?
Thank you.
Eus