Compiler is a software module that translates or converts source code of the program to object code or executable code.
Why it is Needed
As we know that the source code is a code written by the programmer, it cannot be understood directly by the machine (OS), so we need an entity that can convert the human-readable code into machine-readable code. This task is carried out by the compiler.
Responsibility of the compiler
The primary responsibility of the compiler is to convert the source code into machine code (object code or executable code). Along with it, the compiler performs some other tasks side by side. Some other duties which are performed by the compiler are
Checking for errors in the source code.
Prompt alert to the programmer about the errors if any.
Linking of object code modules with the built-in libraries and header files via a linker.
How it works
The compiler read the programming statements from the source code and examine them for any syntactical error. If there are errors in the source code, the compiler identifies them and alerts the programmer about it.
If the source code is free from errors only then the compiler converts the source code into executable code or machine code. This process is known as compilation.
Compile-time & Runtime
Compile time: The time required for the compilation of the source code of a program.
Runtime: The time taken by the program during execution.
This article is from the book
“Patch Up with C”
Get the book or download the app.