Lecture 1 Notes: Introduction 1 Compiled Languages and C++
Lecture 1 Notes: Introduction 1 Compiled Languages and C++
A program goes from text files (or source files) to processor instructions as follows:
Source File Compiler Object File
Linker OS
Executable Program in Memory
Compiler Libraries
Source File Object File
Object files are intermediate files that represent an incomplete copy of the program: each
source file only expresses a piece of the program, so when it is compiled into an object file,
the object file has some markers indicating which missing pieces it depends on. The linker
takes those object files and the compiled libraries of predefined code that they rely on, fills
in all the gaps, and spits out the final program, which can then be run by the operating
system (OS).
The compiler and linker are just regular programs. The step in the compilation process in
which the compiler reads the file is called parsing.
In C++, all these steps are performed ahead of time, before you start running a program.
In some languages, they are done during the execution process, which takes time. This is
one of the reasons C++ code runs far faster than code in many more recent languages.
C++ actually adds an extra step to the compilation process: the code is run through a
preprocessor, which applies some modifications to the source code, before being fed to the
compiler. Thus, the modified diagram is:
Source File P rep ro ces s o r P ro cess ed Co d e Compiler Object File
Linker OS
E x ecut abl e Pro g ram i n M em o ry
P rep ro ces s o r Compiler Libraries
Source File P ro cess ed Co d e Object File
2 Hello World
In the tradition of programmers everywhere, we’ll use a “Hello, world!” program as an entry
point into the basic features of C++.