The C ompilition process

  • A single file C program is processed by the following programs:

    1. The C preprocessor

    2. The C compiler

    3. The C assembler

The compilation process of a C program

Step 1:   run the C pre-processor on the C program

The C pre-processor provide a sophisticated text re-writing system that handles:

  • Inclusion of header files
  • Definition/replacement of constants
  • conditional compilation

The compilation process of a C program

Step 2:   run the C compiler to translate the C source into low level assembler instructions:

  • The C compiler translate the pre-processed C source into low level assembler instructions (still text)

    (Later in this course, we will study programming in assembler code)

The compilation process of a C program

Step 3:   run the assembler to translate the program in assembler instructions into binary machine instructions:

  • The Assembler is a simple program that translate the assembler instructions into low level binary machine instructions (no longer text)

    (This is the executable computer program)

Tasks performed by the C pre-processor

  1. Remove all comments from a C program:

      // comment         ---->    (empty)
      /* ........ */     ---->    (empty)

  2. Read in and process include (header) files:

          #include "header1.h"
     or:  #include <header2.h>

  3. Process the macro (symbolic) definitions:

          #define macroName(x, y)   macro-definition


    .... continued on next slide....

Tasks performed by the C pre-processor

  1. Conditional inclusion (1): include a text segment when some symbol is defined:

      #ifdef symbol 
    
      This text segment is included 
      if "symbol" is defined
    
      #endif

  2. Conditional inclusion (2): include a text segment when some symbol is not defined:

      #ifndef symbol 
    
      This text segment is included 
      if "symbol" is not defined
    
      #endif