To share this page click on the buttons below;
C files
A C program is made of text files (big projects are made by thousands of files). There are 2 kinds of C files: source files and headers files.
Usually source C files have extension .c and header C files have extension .h.
Say you want to write a C program: what you actually do is to write C code into a bounce of source files and header files (shortly source files). But that is not enough: once you finished to type the code, your files need to be converted into an executable.
To obtain an executable you need a special program: the compiler. The compiler takes your source file, processes them and produces the executable. If you made some mistakes in writing the code, the compiler complains and stop to process your files, usually with an obscure error message. You need to fix all the errors and then issue again a compilation.
Actually the compiler is not one single program, but more a suite of different programs used to process your source files. It turns out that the compiler is one of this set of programs, so that we use the name of a part to indicate the whole set.
In the following I will briefly describe the compilation process.
The compilation process
The preprocessor
The first program that processes your files is the pre-processor. The preprocessor works at the level of your text files and operates (following a well defined set of rules) a certain number of substitution within your source files. For the moment I will not go into the details because I just want to give your the pig picture: so just remember that your files are pre-processed before the actual compilation and the preprocessor is able to operate substitution inside your source files.
C source files during the compilation process are pre-processed.
The preprocessor is able to operates substitution inside the source files.
The compiler
The second program that processes your pre-processed source files is the actual compiler. The compiler operates a translation: it takes your text file and produces binary files containg machine code. The binary code is not more readable by human eyes, but it is understandable by the micro-processors.
The compiler translate each .c file into an object file, each object file contains the translation of the .c file in binary code.
The compiler translate the source files into object files.
The linker
The linker is responsible to build your executable. At this point into the object files there is all you have defined in your code (mainly variables and functions), but they are quite unorganized: each object file contains its own functions and variable, but those are not ordered, neither they know about the other variables and functions contained in other object files.
The linker put everything in the right place: it orders all the variables and functions in the correct way and put everything into a single executable file.
The linker takes all the object files and makes the executable by correctly ordering all the functions and variables contained into the object files.
Other compiler programs
There are other programs into the compiler suite, those programs can be used to make different kind of output (like libraries, a collection of functions that can be used by other programs). I will not describe those programs here, just bear in mind that there is more.
To share this page click on the buttons below;