January 4, 2011 6.096
Lecture 1 Notes: Introduction 1
Compiled Languages and C++
Why Use a Language Like C++?
At its core,a computer is just a processor with some memory, capable of running tiny instructions like “store 5 in memory location 23459.” Why would we express a program as a text ﬁle in a programming language,instead of writing processor instructions? The advantages: 1. Conciseness: programming languages allow us to express common sequences of com mands more concisely. C++ provides some especially powerfulshorthands. 2. Maintainability: modifying code is easier when it entails just a few text edits, instead of rearranging hundreds of processor instructions. C++ is object oriented (more on that inLectures 7-8), which further improves maintainability. 3. Portability: diﬀerent processors make diﬀerent instructions available. Programs writ ten as text can be translated into instructions for manydiﬀerent processors; one of C++’s strengths is that it can be used to write programs for nearly any processor. C++ is a high-level language: when you write a program in it, the shorthands are suﬃcientlyexpressive that you don’t need to worry about the details of processor instructions. C++ does give access to some lower-level functionality than other languages (e.g. memory addresses).
A program goes from text ﬁles (or source ﬁles) to processor instructions as follows:
Source File Compiler Object File Linker Source File Compiler Object File Libraries ExecutableOS Program in Memory
Object ﬁles are intermediate ﬁles that represent an incomplete copy of the program: each
source ﬁle only expresses a piece of the program, so when it is compiled into anobject ﬁle,
the object ﬁle has some markers indicating which missing pieces it depends on. The linker
takes those object ﬁles and the compiled libraries of predeﬁned code that they rely on,...