Indirectly, yes.
To know what happens to the code in the header file one must understand how the compiler handles them.
The #include
directive
The #include
directive is a preprocessor directive. Even before the compiler starts to analyze and translate the code it will process all #include
s by inserting the whole code in the given header file to the position of the #include
statement. (You can see what the preprocessor spits out when you use e.g. gcc -E ...
on your source files.)
That is why include guards are important.
So the answer to your question is:
Yes, the code in header files is translated to an object file - to be precise to the object file of the first translated source file which includes it in a translation unit.
The definitions in the header files have to be known in every translation unit which uses the definitions. If you translate your programm file by file and link it afterwards, you will have the code in the header file compiled multiple times. That is why you should put the implementation to a separate source file. If you do that you only will declare each function in every translation unit but not translate the implementation. All files will then be linked to the one object file with the implementation.