C and C++ compilation is (usually) divided in three independent steps:
- Preprocessing, involving macro and #include expansions.
- Compiling, converting source code to binary code and generating intermediante object files.
- Linking, joining the object files in a single ELF or EXE file.
Wherever there is an #include
or a macro, the preprocessor expands that expression with the actual value. In the case of an #include
that entire line is replaced with the .h file contents.
The actual compiler is (usually) not aware of any header file, it sees a compilation unit as a big .c or .cpp file.
The "usually" part comes from the fact that some compilers optimizes header inclusion by storing a precompiled header in some sort of cache, but the effect is the same.