What Does a Compiler Do Anyway?

A compiler translates a program written in the source language (in this case, C or C++) into machine language that a target machine can execute. A typical compiler is structured as follows:

 

1.    The C Preprocessor processes the # C preprocessor directives in a source file.

2.    The compiler proper translates/compiles the source files into assembly files.

3.    The assembler translates assembly files into object files.

4.    The linker combines object files together with any required library files into an executable image file.

 

Some compilers skip assembly file generation and generate object code directly. Some compilers, such as GCC, can perform extensive optimization in the compiler passes, typically in the compiler proper and even in the linker, to reduce code size or execution time, or both.