The higher-level language code is called source code.
The compiled machine language code is
called the target code. The compiler translates the source code into the target machine language.
The beauty of higher-level languages is this: the same C++ source code can be compiled to
different
target platforms.
Editors. An editor allows the user to enter the program source code and save it to files. Most
programming editors increase programmer productivity by using colors to highlight language
features.
• Compilers. A compiler translates the source code to target code. The target code may be the
machine
language for a particular platform or embedded device. The target code could be another source
language; for example, the earliest C++ compiler translated C++ into C, another higher-level
language.
The resulting C code was then processed by a C compiler to produce an executable program.
C++
compilers today translate C++ directly into machine language.
The complete set of build tools for C++ includes a preprocessor, compiler, and linker:
– Preprocessor—adds to or modifies the contents of the source file before the compiler begins
processing the code. We use the services of the preprocessor mainly to #include information
about library routines our programs use.
– Compiler—translates C++ source code to machine code.
– Linker—combines the compiler-generated machine code with precompiled library code or
compiled code from other sources to make a complete executable program. Most compiled
C++ code is incapable of running by itself and needs some additional machine code to make a
complete executable program. The missing machine code has been precompiled and stored in
a repository of code called a library. A program called a linker combines the programmer’s
compiled code and the library code to make a complete program.
We generally do not think about the preprocessor, compiler, and linker working as three separate
programs (although they do); the tools we use make it appear as only one process is taking place:
translating our source code to an executable program.
• Debuggers. A debugger allows a programmer to more easily trace a program’s execution in
order
to locate and correct errors in the program’s implementation. With a debugger, a developer can
simultaneously run a program and see which line in the source code is responsible for the
program’s
current actions. The programmer can watch the values of variables and other program elements
to see
if their values change as expected. Debuggers are valuable for locating errors (also called bugs)
and
repairing programs that contain errors. (See Section 4.6 for more information about
programming
errors.)
• Profilers. A profiler collects statistics about a program’s execution allowing developers to tune
appropriate parts of the program to improve its overall performance. A profiler indicates how
many
times a portion of a program is executed during a particular run, and how long that portion takes
to
execute. Profilers also can be used for testing purposes to ensure all the code in a program is
actually
being used somewhere during testing. This is known as coverage. It is common for software to
fail
after its release because users exercise some part of the program that was not executed anytime
during
testing. The main purpose of profiling is to find the parts of a program that can be improved to
make
the program run faster.
The programming components of the development process are illustrated in Figure 1.1.
Many developers use integrated development environments (IDEs). An IDE includes editors,
debuggers, and other programming aids in one comprehensive program. Examples of IDEs for
C++ include
Microsoft’s Visual Studio 2015, the Eclipse Foundation’s Eclipse CDT, and Apple’s XCode.
1.4 Exercises
1. What is a compiler?
2. How is compiled code different from source code?
3. What tool does a programmer use to produce C++ source code?
4. What tool(s) does a programmer use to convert C++ source code into executable machine
code?
5. What does the linker do?
6. Does the linker deal with files containing source code or machine language code?
7. What does the preprocessor do to source code?
8. List several advantages developing software in a higher-level language has over developing
software
in machine language.
9. How can an IDE improve a programmer’s productivity?
10. Name a popular C++ IDE is used by programmers developing for Microsoft Windows.
11. Name a popular C++ IDE is used by programmers developing for Apple macOS.