Back to C programming

The Compiler

The C compiler translates C-source-code into machine code.

The Compiler translates each source file into an object file also known as a module.

If there are more that 1 object files, these are then linked by the linker which outputs a executable.

The executable is what we normally run as a program in the system.

The Translation Phases

The compilation takes place in 8 steps.
  1. Read Source
    • Convert the File Charset into Source Charset if necessary
    • Convert end-of-line indicators to newline chars if needed
    • Trigraphs are converted to their single char versions
    • Digraphs are left as they are.
  2. whenever a backslash is followed by a newline character, it is deleted
  3. Source is Broken in Tokens.
    • each Comment is converted into a space.
  4. Preprocessor Directives are carried out and macro calls are expanded
  5. It is the converted into the Execution Character Set
    • all character and escape sequences in char constants and strings converted.
  6. Adjacent String Literals are concatenated
  7. Compiling Begins and the tokens are converted into Machine Code
  8. The Linker is invoked
    • it resolves references to external objects and functions
    • generates the executable file
    • External objects and functions should not be defined more than once

Compiling Programs

use make when you can. Assume you have a file, file.c, then:
make file
or
CFLAGS="-Wall" make file
use a makefile named "Makefile":
CFLAGS=-Wall -g

clean:
  rm -f file

http:///wiki/?thecompiler

27aug21   admin