Understanding the gcc Compiler.
Remember: “gcc is a compiler for C code”
The GCC has 4 parts or phases that are described below:
1. Preprocessing: This is the first stage of the Gcc. It refers to all initial definitions in the C file that will allow substitutions later in the code.
E.g: #def, #undef, #error, #include, etc.
2. Compilation: This is the second stage of the Gcc, here the high-level language that has been defined in the previous stage, becomes machine language (López, Jeder, Vega, 2009). This stage is divided into 4 phases that are described below: i) lexical analysis, ii) syntactic analysis, iii) semantic analysis and iv) code generation.
Lexical analysis: the compiler checks if the language is valid to perform the operation, extracting the character string that it identifies as valid vocabulary. Otherwise, it issues error messages.
Syntactic analysis: it relates the parts of code in an orderly way. The representation is usually a tree.
Semantic analysis: From the defined structure, the compiler reviews the logic in what is implicit, it tries to identify possible violations of the semantics or meaning of the programming language.
Code generation: in this last phase, a logical representation (intermediate machine language) is created, and it involves optimizing the code that is being generated.
3. Assembled: This is the third stage of the Gcc. When the 4 phases of the compilation are approved, an object code is created.
4.Linking: Finally, in this stage the object code that has been compiled in the previous stages is linked-up (without any type of error) and ties it with the variable that is outside said code, in this way you can run altogether.
This process looks like this