Programmers do not spend weeks or months blindly programming into a text box, and then one day click the Execute button and things inevitably work as intended. Instead, they program in blocks. They write a few lines or segments of C++, and then click Execute to see the current results and how that block works. When they click Execute, something happens-the code is compiled. In other words, it is translated into a form the computer can understand and execute as a program. In order for the translation to be successful, the C++ source code must be valid. Thus, mistakes such as spelling errors or other kinds of language errors are not acceptable to the compiler. These are called syntax errors and are rejected by the compiler during the process of compilation. Later chapters explain the details of the C++ language.
If such syntax errors are encountered, the compilation might continue for a while or end immediately. In any case, at some point compilation will stop and the program will not be executed because mistakes were found in the source code. As a mistake is found, the compiler adds it to a list of errors, and eventually it's the job of the programmer to cycle through the list and to correct all those errors. The errors must be addressed before compilation will be successful. If compilation is successful, then the program can be taken for a test run, that is, tried out and tested.
Note | C++ also generates warnings in addition to errors. Errors will cause compilation to stop, and the program cannot be executed while those errors remain. Warnings, however, do not cause compilation to stop, do not cause errors, and do not stop the program from running. Warnings represent valid C++, but exist to draw your attention to specific parts of the code because it might not run as intended. |
To compile an application in Visual Studio .NET, press F5 or click Build | Build Solution. The window at the bottom lists the compilation progress; either compilation will be successful or errors will be listed.
Figure 4.11
To compile an application using Code::Blocks, press Ctrl+F9 or click Build | Build. The Messages window at the bottom lists the compilation progress; either compilation will be successful or errors will be listed.
Figure 4.12
To compile an application using Dev C++, press Ctrl+F9 or click Execute | Compile. The Compile Progress window shows the compilation progress; either compilation will be successful or errors will be listed.
Figure 4.13