<< Chapter < Page Chapter >> Page >
An explanation of how an IDE processes a source code file into a program that runs on the computer. Categories of errors are discussed and demonstrated with C++ source code files that can be downloaded for practice.

Ide overview

High-level language programs are usually written (coded) as ASCII text into a source code file. A unique file extension (Examples: .asm .cob .for .pas .c .cpp) is used to identify it as a source code file. As you can guess for our examples – Assembly, COBOL, FORTRAN, Pascal, "C" and "C++" however, they are just ASCII text files (other text files usually use the extension of .txt). The source code produced by the programmer must be converted to an executable machine code file specifically for the computer’s CPU (usually an Intel or Intel compatible CPU within today’s world of micro computers). There are several steps in getting a program from its source code stage to running the program on your computer. Historically, we had to use several software programs (a text editor, a compiler, a linker and operating system commands) to make the conversion and run our program. However, today all those software programs with their associated tasks have been integrated into one program usually called a compiler. However, this one compiler program is really many software items that create an environment used by programmers to develop software. Thus the name: Integrated Development Environment or IDE.

The following figure shows the progression of activity in an IDE as a programmer enters the source code and then directs the IDE to compile and run the program.

Integrated Development Environment or IDE

Upon starting the IDE software the programmer usually indicates he wants to open a file for editing as source code. As they make changes they might either do a "save as" or "save". When they have finished entering the source code, they usually direct the IDE to "compile&run" the program. The IDE does the following steps:

  1. If there are any unsaved changes to the source code file it has the test editor save the changes.
  2. The compiler opens the source code file and does its first step which is executing the pre-processor compiler directives and other steps needed to get the file ready for the second step. The #include will insert header files into the code at this point. If it encounters an error, it stops the process and returns the user to the source code file within the text editor with an error message. If no problems encountered it saves the source code to a temporary file called a translation unit.
  3. The compiler opens the translation unit file and does its second step which is converting the programming language code to machine instructions for the CPU, a data area and a list of items to be resolved by the linker. Any problems encounted (usually a syntax or violation of the programming language rules) stops the process and returns the user to the source code file within the text editor with an error message. If no problems encountered it saves the machine instructions, data area and linker resolution list as an object file.
  4. The linker opens the program object file and links it with the library object files as needed. Unless all linker items are resolved, the process stops and returns the user to the source code file within the text editor with an error message. If no problems encountered it saves the linked objects as an executable file.
  5. The IDE directs the operating system’s program called the loader to load the executable file into the computer's memory and have the Central Processing Unit (CPU) start processing the instructions. As the user interacts with the program, entering his test data, he might discover that the outputs are not correct. These types of errors are called logic errors and would require him to return to the source code to change the algorithm.

Resolving errors

Despite our best efforts at becoming perfect programmers, we will create errors. Solving these errors is known as debugging your program. The three types of errors in the order that they occur are:

  1. Compiler
  2. Linker
  3. Logic

There are two types of compiler errors; pre-processor (1st step) and conversion (2nd step). A review of Figure 1 above shows the four arrows returning to the source code so that the programmer can correct the mistake.

During the conversion (2nd step) the complier might give a warning message which in some cases may not be a problem to worry about. For example: Data type demotion may be exactly what you want your program to do, but most compilers give a warning message. Warnings don't stop the compiling process but as their name implies, they should be reviewed.

The next three figures show IDE monitor interaction for the Bloodshed Dev-C++ 5 compiler/IDE .

Compiler Error (the red line is where the complier stopped)
Linker Error (no red line with an error message describing linking problem)
Logic Error (from the output within the "Black Box" area)

Demonstration program in c++

Creating a folder or sub-folder for source code files

Depending on your compiler/IDE, you should decide where to download and store source code files for processing. Prudence dictates that you create these folders as needed prior to downloading source code files. A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

  • Demo_Programs

If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

Download the demo program

Download and store the following file(s) to your storage device in the appropriate folder(s). Following the methods of your compiler/IDE, compile and run the program(s). Study the soruce code file(s) in conjunction with other learning materials.

Download from Connexions: Demo_Pre_Processor_Compiler_Errors.cpp

Download from Connexions: Demo Compiler_Conversion_Errors.cpp

Download from Connexions: Demo_Linker_Errors.cpp

Download from Connexions: Demo_Logic_Errors.cpp

Definitions

text editor
A software program for creating and editing ASCII text files.
compiler
Converts source code to object code.
pre-processor
The first step the complier does in converting source code to object code.
linker
Connects or links object files into an executable file.
loader
Part of the operating system that loads executable files into memory and direct the CPU to start running the program.
debugging
The process of removing errors from a program. 1) compiler 2) linker 3) logic
warning
A compiler alert that there might be a problem.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Programming fundamentals - a modular structured approach using c++. OpenStax CNX. Jan 10, 2013 Download for free at http://cnx.org/content/col10621/1.22
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals - a modular structured approach using c++' conversation and receive update notifications?

Ask