Chapter 5. Functional Literacy

C++ was intended to be useful in writing large programs. Such programs are usually composed of many implementation files, as I mentioned in Chapter 3.

In such a case, we must have some way of creating an executable program (sometimes abbreviated to just an executable) from a number of implementation files. We also need some way for code in one module to refer to code in another one. Similarly, we have to be able to specify where execution of our program should start; this is taken care of by the C++ rule that execution always starts at the block called main.

As we've already seen, the computer can't execute source code. Therefore, any implementation files we write have to be translated into object code; the result of such translation is an object code module. One other kind of module we're interested in is the library module, which contains the object code from several implementation files.

The idea of various types of modules led to the following discussion with Susan:

Susan: So an object file is like some kind of interface between your code and the binary numbers of the machine? I am confused.

Steve: Each implementation file is translated by the compiler into one object file. Then these object files will be combined along with some previously prepared library files to make an executable program.

Susan: iostream is a library? So are these already written programs that you can refer to like a real library?

Steve: Yes. Actually, iostream is now part of the C++ standard library; that happened a few years ago when they standardized the library.

Susan: The libraries contain code segments that are generalized, and the other modules contain code segments that are program specific?

Steve: Right. One point that should be emphasized, though, is that a library contains object code, not source code.

Susan: Where is the library? I am serious.

Steve: You can have more than one library, including ones written for more specialized purposes by different companies. The library files for the compiler on the CD in the back of the book are kept in a subdirectory under the directory where the compiler is installed.

Susan: So what is an "implementation file"? Is it a set of code written by the programmer?

Steve: It's a file containing part of a program, in source code. Most significant programs consist of a number of modules (files), rather than one big module (file), partly because it's easier to find and edit one logical segment of a program in a separate file than a whole bunch of code all in one big file.

Susan: Okay then, so a module is just a big logical segment? How is it delineated from the rest of the program? Is it named? How do you find it? Can you just tell by looking where a module starts and ends?

Steve: A module, in C++ terminology, is another name for a file. Therefore, an implementation module is an implementation file, which contains program statements. It has a name, which is the name of the file.

Susan: So an implementation file is like a library, only as we have discussed it is more specific than a library; it is for the program that you are working on?

Steve: Right.

Susan: Where are these modules and how do they get there?

Steve: Wherever you (or whoever wrote the code) put them. In the case of your "weight-writing" program, the code you wrote is in an implementation file. That module is compiled to make an object code module, which is then combined with library module(s) that come with the compiler to make an executable file that can be run.

Susan: So then the implementation file is a "miniprogram" within a program that holds the source code to be later compiled?

Steve: It contains part of the source code of a program, which needs to be compiled and combined with other previously compiled code before it can be used. I think that's the same as what you're saying.

Actually, I've misused C++ terminology a little here in the interests of comprehensibility. The term block isn't quite correct as applied to main(); the correct term is function. Let's take a look at the difference between these two concepts, some other related definitions, and the objectives of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset