April 2, 2018

C Preprocessor

C Preprocessor:
Preprocessor works on the command given to it in source code file. It transforms source code before it is passed to the compiler. The commands for preprocessor are called preprocessor directive.
Preprocessor Directive can be given using inclusion macro and file inclusion using #define and #include.

Example:
Preprocessor directives begin with # symbol.

#include<stdio.h>
#include “myfile.h”

#define MAX 10


Macro: We can define a macro using #define.

Build process

Build Process: C's program goes through several stages before being executed. Several files are built before the code is executed.

Source Code: The code written in high level language is source code. Editor is the platform where source code is written. In C and C++ source code file is saved as .C and .CPP extension.

Expanded Source Code: Preprocessor takes source code as an input and creates expanded source code file ( .I file).
     *Preprocessor works on the command given to it in source code file. The commands for preprocessor are called preprocessor directive.
We will discuss pre-processor directive in separate posts.

Object Code: Expanded source code goes as an input to Compiler which translates it into object code ( .obj file ) which is machine like code.

Executable Code: The object code generated by compiler from source code is not stand-alone which means it does not contain complete information for execution as some of the information is predefined in library files which contains object code of predefined methods. These library files of object codes and object code of our program or source code can collectively be performed or executed by system. Linker performs this task which combines object codes of library files with our object file and generate executable code ( .exe file ).
    *Any task can be performed only in main memory. So Loader loads the executable code into main memory.