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.
- 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.
- whenever a backslash is followed by a newline character, it is deleted
- Source is Broken in Tokens.
- each Comment is converted into a space.
- Preprocessor Directives are carried out and macro calls are expanded
- It is the converted into the Execution Character Set
- all character and escape sequences in char constants and strings converted.
- Adjacent String Literals are concatenated
- Compiling Begins and the tokens are converted into Machine Code
- 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
