C++: The Complete Reference



addresses for the various machine-code instructions have not been absolutely
defined--only offset information has been kept. When your program links with the
functions in the standard library, these memory offsets are used to create the actual
addresses used. There are several technical manuals and books that explain this
process in more detail. However, you do not need any further explanation of the
relocation process to program in C++.

Many of the functions that you will need as you write programs are in the standard
library. They act as building blocks that you combine. If you write a function that you
will use again and again, you can place it into a library, too.

Separate Compilation
Most short programs are completely contained within one source file. However, as a
program's length grows, so does its compile time (and long compile times make for
short tempers). Hence, C/C++ allows a program to be contained in many files and lets
you compile each file separately. Once you have compiled all files, they are linked,
along with any library routines, to form the complete object code. The advantage of
separate compilation is that if you change the code of one file, you do not need to
recompile the entire program. On all but the simplest projects, this saves a substantial
amount of time. The user documentation to your C/C++ compiler will contain
instructions for compiling multifile programs.

Understanding the .C and .CPP File Extensions
The programs in Part One of this book are, of course, valid C++ programs and can be
compiled using any modern C++ compiler. They are also valid C programs and can be
compiled using a C compiler. Thus, if you are called upon to write C programs, the
ones shown in Part One qualify as examples. Traditionally, C programs use the file
extension .C, and C++ programs use the extension .CPP. A C++ compiler uses the file
extension to determine what type of program it is compiling. This is important because
the compiler assumes that any program using the .C extension is a C program and that
any file using .CPP is a C++ program. Unless explicitly noted otherwise, you may use
either extension for the programs in Part One. However, the programs in the rest of
this book will require .CPP.

One last point: Although C is a subset of C++, there are a few minor differences
between the two languages, and in a few cases, you may need to compile a C program
as a C program (using the .C extension). Any instances of this will be noted.

12