Introduction to Compiler

The essential thing you need to do, before learning any programming language like C++, is to make sure that you have a compiler

What is a compiler?

Computers understand only 1 language which is consists of sets of instructions made with help of 0 and 1. This language is known as machine language.

A instruction to a computer could look like this:

10001001 01000100

As you can imagine, programming a computer directly in machine language using only ones and zeros is very difficult. To make programming simple and easier , high level languages have been developed. High level programs also make it easier for programmers to understand the program.

So, In short A compiler is a program that reads the code written in a high-level language and produces an executable that the CPU can understand. To run the executable you will not require the compiler.

#include <iostream>
using namespace std;
int main ()
{
  cout << “Hello World! \n”;
  std::cout << “Hello World\n”;
  return 0;
}

Even if you cannot really understand the code, you should be able to appreciate how much easier it will be to program in the C++ language as opposed to written in one and zeros.

Computer can only understand one and zeros and humans wish to write in low level languages have to be re-written (translated) into one and zeros at some point. This is done by programs which is known as compiler, interpreter, or assembler.

It turns the program code into an executable that your system can actually understand and run.

How Compiler Works

The Compiler replaces all statements with a sequence of machine instruction. When the program has been compiled the resulting machine code is saved as executable file whose extension is exe.But in system that process also required to do many work which is explained through given image.

Object code file extension

Object file consist of statements and function definition that are defined in ones and zeros. Object files are not executable by themselves. In some operation system the file extension for Object file is .obj and .o

Linker

It is a program that takes one or more object files generated by a compiler or interpreter and combines them into a one executable file.In that process it combine the C library file and object file to create a one executable file with the help of loader which shown in image.

Binary executables file extension (.exe)

.exe file produced as the output of the program which is produced by linker. In unix operating system Binary executable files does not have any extensions. In other operating system like window has .exe as extension.

 

What is a interpreter ?

An interpreter is also a program that reads the code that compiles and executes the program.

The advantages of the interpreter are they are easy to write the program than the compilers. The reason is interpreters are written in a high-level language.

The disadvantage is they are less efficient because they need to compile every time the program is run. 

Any language can be compiled or interpreted; however, high-level languages like C, C++, and Pascal are compiled, whereas “scripting” languages like Perl and Javascript are interpreted.

The below are the properties of high-level languages:

1) These are much easier to read and write.

2) Requires instructions to perform the same task as lower-level languages.

3) No need to worry about the details such as loading variables into CPU registers. The compiler or interpreter takes care of all those details for you.

4) They are portable to different architectures; the exception to portability is that many platforms, such as Microsoft Windows, contain platform-specific functions that you can use in your code. These can make it much easier to write a program for a specific platform but at the expense of portability.

5) C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

6) This is a platform-independent language; it supports Windows, Linux, Mac OS, and the various versions of UNIX. This reference will take you through a simple and practical approach while learning the C++ Programming language.