Home | C++ Tutorial | 2. Setup |     Share This Page
The skill that makes your computer think

Introduction to C++

I chose C++ for this tutorial because it is an advanced, powerful language, yet it is relatively easy to introduce and learn. Another reason I chose it is because most modern, high-performance computer programs are written using C++. Yet another reason is because C++ is not owned by a corporation. Java (a very advanced language, one receiving much well-deserved attention) is owned by Sun Microsystems, who has sole control over it, and who expects to make a profit from it eventually. Visual Basic is owned by Microsoft, resulting in many of the same limitations. C++ is owned by no one, therefore it is owned by everyone.

By the way, don't get confused — Microsoft's product Visual C++ is not C++. They are different things. One is a computer language, the other is a consumer product that embodies a version of C++ geared to a particular operating system — Windows.

This tutorial teaches C++. If you learn C++, you can also learn Visual C++. The reverse is not necessarily true.

Each major platform has a C++ compiler, some have several. If you run Windows, you can acquire a C++ compiler for free. For Linux and other versions of Unix, a C++ compiler is most likely already installed.

C++ knows about objects (an advanced topic that will be touched upon in this tutorial) and therefore can teach sound programming techniques from the very beginning.

C++ is a compiled computer language. This means the original source code is translated into a specific machine's native tongue, all at once, before the program is run. The program the computer runs is composed entirely of instructions known to it, requiring no further interpretation.

Source Code
#include <iostream>

using namespace std;

int main()
{
	cout << "Bonjour Monde!" << endl;
	return 0;
}
                  
Compiler
A compiler is a very specialized computer program that translates source code into machine-specific code. Compiler writing is very difficult and esoteric, and is one of the more advanced and complex parts of computer science.

It is not too much to say that a compiler writer is to a computer programmer as a computer programmer is to someone who thinks they speak Latin in Latin America.
Machine-Specific Code
F000:0000 F0            LOCK
F000:0001 8AC4          MOV     AL,AH
F000:0003 9A5CF000F0    CALL    F000:F05C
F000:0008 EBEA          JMP     FFF4
F000:000A 8AC2          MOV     AL,DL
F000:000C 02C6          ADD     AL,DH
F000:000E 52            PUSH    DX
F000:000F BA8103        MOV     DX,0381
F000:0012 9AD44500F0    CALL    F000:45D4
F000:0017 5A            POP     DX
F000:0018 5A            POP     DX
F000:0019 59            POP     CX
F000:001A 58            POP     AX
F000:001B CB            RETF
F000:001C 56            PUSH    SI
F000:001D D000          ROL     BYTE PTR [BX+SI],1
F000:001F F0            LOCK
F000:0020 82D000        ADC     AL,00

	... and so on, for hundreds of lines.
                  

The other major approach to running a computer program is called interpretation. An interpreter converts a computer program into the host machine's native tongue, instruction by instruction, as the program runs. This is a nice environment in which to write programs, but if the program is simply used and is no longer being developed, much time is wasted re-interpreting instructions that could be translated just once and stored in translated form.

Because a compiler translates the entire program at once, compiled programs are faster than interpreted programs, and are preferred for tasks that require high performance.

There are two principal reasons for high-level languages like C++. The first is to make program development easier — each instruction written in C++ might represent dozens or hundreds of lower-level native instructions. The second is to make programs portable — if sufficient care is taken in development, a program written for one computer can be re-compiled and run on another. Therefore, a programmer need only learn one computer language, instead of one language per computer architecture. If a single program can be run on any machine, the unit price of software can go down.

It would be nice if there were an interpreted version of C++, for program development work only, so the developer would not have to re-compile after each trivial change. But this hasn't happened yet, and in any case it would probably be an expensive environment. One of my goals in this project is to cost the student nothing.

Because of my wish for quick feedback to the student, in this tutorial you will find pages with programs that appear to run instantly, at each keystroke. These are actually JavaScript programs, not C++ programs. I use them whenever the immediate response of JavaScript is desirable, and when the similarity between JavaScript and C++ allows one to reasonably imitate the other.

Each of the JavaScript demonstration program that imitates a feature of C++ can be created in C++ as well, and many of the JavaScript demonstration programs are accompanied by equivalent C++ source listings, so you can compile and test in C++, to discover for yourself what the differences are.

Finally, to answer what is certainly the question most often asked by students — “Shouldn't I learn C before C++?” The answer — no, not unless you think you need to know how to ride a horse before learning how to ride a motorcycle. Or unless you think you should learn German, French and Latin before learning English (thus learning some of the pieces from which English is constructed). The second is actually a great idea, if you have the time. But no one seems to. It's the same with programming.

This tutorial presumes some familiarity with computers and programming. If you have never written a computer program in any language before, if you think computers can get along fine without the added complexity of programs, this tutorial may not be for you.


These pages are Copyright © 2000, P. Lutus. All rights reserved.

www.arachnoid.com Main Page
Home | C++ Tutorial | 2. Setup |     Share This Page