Overview of C processing

When a file with C code (usually with a .c extension) needs to be compiled it runs through a number of tools. The main tool is called compiler (or driver) and it drives everything.

  1. First the compiler reads the C file into memory. If it detects include files it starts the C preprocessor which will read those files into memory as well.

  2. Include files are macro files which need to be processed by a macro processor. This used to be a generic macro processor like m4 but is nowadays aware of C syntax.

  3. Header files are now concatenated with the processed code from the .c file. Now the compiler can compile the whole code and the result is either a file with object code (a .o extension) or an executable program.

  4. If the goal is an executable program, the compiler calls the linker to resolve unresolved externals (e.g. if your program code calls functions from other libraries or other files (modules) in your program). Once the linker is done an executable file has been generated.

  5. In case of the object code (.o file) we now have a component that can go into an archive waiting to be linked together with other object code to form a new executable program.

  6. Sometimes linking does not produce a big self-contained executable but an executable that needs so called Dynamic Link Libraries (windows: .dll) or Shared Object libraries (Unix: .so) at runtime.