Commentary: Straight-Line Computation in C++

Steven Zeil

Last modified: Aug 31, 2017
Contents:

These commentary documents are intended to accompany your readings from the your textbook as you review C++ material. This is not a “web course”, and these commentaries are not trying to teach you the material.

They will include some notes on things that you might find strange or unintuitive if you come to C++ from Java (probably the most common case for students reading this website) or from Python.

These commentaries may also include some notes on things that, in my experience, some C++ students just find difficult in general, regardless of their background. I may also point out things that have changed in recent versions of C++.


Each section of this website includes chapter numbers from Malik’s C++ Programming: From Problem Analysis to Program Design, the textbook used for our CS150, CS250, and CS330 courses. If you are reading this website in preparation to take CS250, you might as well go ahead and get this book, as you will need it anyway.

If you prefer to wait, though, and use some other C++ text that you already have on hand, that’s OK. But then you will have to figure out the corresponding chapters. Use the list of What You Need to Know for each module to guide your search for the appropriate chapters.

1 Processing C++ Programs

All programs, whatever the language, start outs as plain text source code that a program writes using some kind of editor. The major steps involved in turning C++ source code into somethign you can execute are:

  1. The source code is preprocessed to fetch differnet files that need to be included together.

    Preprocessing modifies the text of the source code (though it does not change the original files supplied by the programmer). The result is still plain text and is still considered source code.

  2. The preprocessed source code is compiled to produce object code.

    Object code is close to executable machine code. However, most programs do not stand alone but make use of functions and other components provided by other code that will have been compiled separately.

    The compiler does not know where these components reside within their own object code, so it includes a list of names of things that this code uses but that need to be located elsewhere. It also has a list of names of things that it provides and the locations where it has stored each of them.

  3. The object code is linked to form the executable.

    Linking is the process of taking multiple pieces of object code, each of which has a list of things it need and a list of things that it provides, and joining them together, so that all needed components are matched up against a component provided somewhere.

At the end of this process, you have an executable file, a file of machine code ready to load and run.

If you are a C programmer
If you are a Java programmer
If you are a Python programmer

2 Data Types

A data type is a collection of possible values, on which we can perform a certain set of operations.

All programming languages start with a certain set of pre-defined data types, such as characters, strings of characters, amd various kinds of numbers. Modern programming languages also allow programmers to define new data types to serve the needs of a particular program.

If you are a C programmer
If you are a Python programmer
If you are a Java programmer