The header file itself (as a separate entity) is not compiled.
It's presence in the executable (if it has any) will be via any #include statements in the source code. At compile time, the source the compiler sees is your prog.cpp with all the #include file's spliced in appropriately.
A header file containing only declarations won't have any visible imprint on the executable, except for perhaps appearing as a name in the debug information.
Eg.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// something.h
extern void something();
// something.cpp
#include "something.h"
void something( ) {
// do something
}
// main.cpp
#include "something.h"
int main( ) {
something(); // do something
}
| |
However, if the header file contains things like inline functions, class member function definitions, templates, then things start to get interesting.
1 2 3 4 5 6 7 8
|
// something.h
extern void something();
class Foo {
void method() {
// stuff
}
};
| |
If nothing ever creates an instance of Foo and calls method(), then (at least in GCC), the compiled implementation of method() is not in the executable.
Historical early C++ compilers had a bit of a reputation for code bloat, but modern compilers should only give you what you actually
use in the code.