Compilation is a three-phase process: preprocessing, compilation and linking.
The preprocessor's job is to prepare a source file (translation unit) for compilation. This is achieved by reading each source file, stripping out the user-comments, performing macro substitutions and acting upon any conditional compilation directives, writing the output to an intermediate file which contains only C code and nothing else. Thus there will be one intermediate file generated for each translation unit.
The compiler's job is to create an object source file from an intermediate file. Object source files primarily consist of a machine code translation of the C source code followed by the symbol tables, which lists all the internal and external linkages of the translation unit. An external linkage is simply a type declaration which is not defined within the current translation unit; the definition may be provided by a type library or it may be provided by another translation unit. Either way, the compiler cannot generate the required machine code, so it uses a symbol (a placeholder) instead.
Once all translation units are compiled to object files, the linker examines the linkage tables and uses that information to generate a single machine code executable from the object source, substituting the placeholders generated by the compiler and adjusting memory offsets to suit the resultant code.
Chat with our AI personalities