Sams Teach Yourself C++ in 21 Days

(singke) #1
In time, higher-level languages evolved, such as BASIC and COBOL. These languages
let people work with something approximating words and sentences (referred to as
source code), such as Let I = 100. These instructions were then translated into machine
language by interpreters and compilers.
An interpretertranslates and executes a program as it reads it, turning the program
instructions, or source code, directly into actions.
A compilertranslates source code into an intermediary form. This step is called compil-
ing, and it produces an object file. The compiler then invokes a linker, which combines
the object file into an executable program.
Because interpreters read the source code as it is written and execute the code on the
spot, interpreters can be easier for the programmer to work with. Today, most interpreted
programs are referred to as scripts, and the interpreter itself is often called a “script
engine.”
Some languages, such as Visual Basic 6, call the interpreter the runtime library. Other
languages, such as the Visual Basic .NET and Java have another component, referred to
as a “Virtual Machine” (VM) or a runtime. The VM or runtime is also an interpreter.
However, it is not a source code interpreter that translates human-readable language into
computer-dependent machine code. Rather, it interprets and executes a compiled
computer-independent “virtual machine language” or intermediary language.
Compilers introduce the extra steps of compiling the source code (which is readable by
humans) into object code (which is readable by machines). This extra step might seem
inconvenient, but compiled programs run very fast because the time-consuming task of
translating the source code into machine language has already been done once, at com-
pile time. Because the translation is already done, it is not required when you execute the
program.
Another advantage of compiled languages such as C++ is that you can distribute the exe-
cutable program to people who don’t have the compiler. With an interpreted language,
you must have the interpreter to run the program.
C++ is typically a compiled language, though there are some C++ interpreters. Like
many compiled languages, C++ has a reputation for producing fast but powerful
programs.
In fact, for many years, the principal goal of computer programmers was to write short
pieces of code that would execute quickly. Programs needed to be small because memory
was expensive, and needed to be fast because processing power was also expensive. As
computers have become smaller, cheaper, and faster, and as the cost of memory has

6 Day 1

Free download pdf