4/1/14 ¡ 1 ¡
Writing Large Programs
Based on slides from K. N. King and Dianna Xu Bryn Mawr College CS246 Programming Paradigm
The Compilation Process
- Preprocessing:
- processes include-files, conditional compilation and macros.
- Compilation:
- takes the output of the preprocessor and the source code, and
generates assembler source code, i.e., making .s file.
- Assembly:
- takes the assembly source code and produces an assembly
listing with offsets. The assembler output is stored in an
- bject file, i.e., .o file.
- Linking:
- takes one or more object files or libraries as input and
combines them to produce a single (usually executable) file.
Compilation Compiler/Assembler and Linker
- Compile green.o: cc –c green.c
- Compile blue.o: cc –c blue.c
- Link together: cc green.o blue.o
Multiple Source Files
- The decision to divide your program into multiple
source files is not only a matter of size.
- One and only one .c file must contain a main.
- Functions that handle some common aspects of a
program should be grouped into the same file.
- main, data structure implementation (i.e. linked
list), I/O, utilities, display/GUI, etc
Header Files
- How can a function in one file call a function
that’s defined in another file?
- How can a function access an external variable in
another file?
- How can two files share the same macro definition
- r type definition?
- The #include directive tells the preprocessor to