'Pre Processor' - What Is It?

compiler does two jobs pre-processor and translator. what does pre processor do

Replies

  • Neeraj Sharma
    Neeraj Sharma
    As far as I know, a program is passed to the pre-processor before it is executed or in other words before its processing begins. The pre-processor is involved in the task of linking the libraries. For example, consider a C program

    #include
    int main()
    {
    printf("Hi there");
    }

    #include is a pre processor there which helps in including the header file in the program before the execution begins. If the header file is not included then printf will have no meaning in the program as the definition of printf is in stdio.h header file. Same is the case with including string.h for using string handling functions like strlen(), strcat() etc.
  • aarthivg
    aarthivg
    In the book written by Gilberg, It states that preprocessor reads the source code and prepares it for the translator. While preparing, it scans for the special code called preprocessor commands.
    #-Link-Snipped-#, this preprocessor command is what you say as, checking for header files, whether it is included in the program or it helps to include header file.
  • lovejeet
    lovejeet
    the main task of compiler is translation. that is, compiler is a type of translator which translates high level language into machine language. now, according to the gilberg in his book, the 1st phase of compiling is lexical analysis(there are seven such phases). the lexical analysis reads the source code, scans it and arranges it in tokens. so what preprocessor commands are the commands included in the program to include header file and other files or to define macros. correct me if i am wrong.
  • aarthivg
    aarthivg
    lovejeet
    the main task of compiler is translation. that is, compiler is a type of translator which translates high level language into machine language. now, according to the gilberg in his book, the 1st phase of compiling is lexical analysis(there are seven such phases). the lexical analysis reads the source code, scans it and arranges it in tokens. so what preprocessor commands are the commands included in the program to include header file and other files or to define macros. correct me if i am wrong.
    what is lexical analysis,tokens and macros?

    I have just started learning 'c' (only two days old😉 ). So please try to be in simple words😀
  • Neeraj Sharma
    Neeraj Sharma
    Lexical analysis divides the code in simple parts like c=a+b can be divided as a combination of tokens where c,=,a,+,b are called tokens or lexemes.

    Macro is another type of pre processor. As #include is used for including files, macro is used to have an alternate definition or kind of substitution .
    #define pre processor is used for defining a macro
    #define PI 3.14
    signifies that wherever you mention PI in your program, it will be replaced by 3.14 at the time of calculation.
    A compiler has following phases:
    Lexical Analysis, Syntax Analysis, Semantics Analysis, Intermediate Code generator, Code Optimizer, Code Generator.

You are reading an archived discussion.

Related Posts

Name-Tashnif Rubayet Hey friends I am from India and I am doing my engineering in Mechanical.I am still a student but after completing my degree I really want to join...
Hi my self Rafay zafar khan, please help me to find out the registration mean the owner of cell phone number in Pakistan or at least the current location of...
WHAT IS THE ROLE AND WORK TO BE PERFORMED MY A GRADUATE ENGINEER TRAINEE
Look at craziness about new gadget Specs: 2.3GHz Intel i7 quad core 8BG RAM​256GB Flash Storage​1GB Nvidia GeForce GT650M ​2880×1800 Resolution with 220 PPI​(Apple:the world's highest resolution display)​Isn't it too...
Can Somebody Please enlighten me up about working of various parts of engine in valve timing. I need to know about whole working of Camshaft, Rocker arm, push rods, tappets...