When you translate the source code in .c you transform it into machine code

+---------------+
| source code .c|
+---------------+
           |
           |
           v
+----------------------------------+
|  compilator & linking of c code  |
+----------------------------------+
           |
           |
           v
+---------------+
| Machine Code  |
+---------------+

When creating an executable from a C file, there are 2 mandatory steps:

  • compilator
  • linking

mean: The preprocessor is given instructions, we call these instructions “preprocessor directives”

the compilation is divided into 2 steps:

  • preprocessor (source files .c or .h + preprocessor directives with the c source code content, It is written next to the code, not outside or apart)
  • processor (lexer + parser) (source files without directives preprocessor)

At one time, the preprocessor was something new and very helpful, but today it is not very useful and seems somewhat complex.

With the preprocessor directives you can copy all the text from one source code file to another file.

You can also replace a piece of text that is repeated with another, you can create new, easier functions and other things.

The preprocessor takes the preprocessor directives and operates or manipulates the C source code file itself (.c or .h) and generates a new, preprocessed and modified C file from the original without the preprocessor directives.

The .c source code processor has 3 steps:

  1. compilator c (preprocessor) (.c to .c)
  2. compilator c (processor) (.c to .o)
  3. linker c (.o to executable)

According to the book “The C Programming Language” (Second Edition) in Spanish and page 97

It is a first step separate in the compilation

c provides certain language facilities through a preprocessor

examples:

  • #include
  • #define
  • conditional compilation (if you want to compile something for a certain hardware architecture or not)
  • macros with arguments

examples:

define PI 3.1416
#include <stdio.h>
#if defined(CREDIT)
    credit();
#endif
#ifdef DEBUG
    printf("debug actived\n");
#endif
pragma once