What is C Compiler & How it works?

Discussion in 'C' started by lionaneesh, Jun 9, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India

    What is a Compiler


    A Compiler is a Computer Program that go through the provided source code , Checks for error and converts in into another computer language that a computer can understand (usually binary opcodes).

    Compilation


    A compiler's work can be divided into 3 parts.
    1. Front End
    2. Middle End
    3. Back End
    Front End

    The Front end first starts with the Preprocessor phase , Which includes handling #define , #include etc directives then it passes to lexical analyser which checks whether the source code is correctly writen on the basis of language's syntax.
    If error or warnings are forund the compiler reports it and kills the execution.

    For eg :-
    Code:
    #include<stdio.h>
    int main()
    {
    return(0);
    
    
    So in this example we'll be taking a piece of incomplete code , It basicaly misses a closing '}' braces .

    Lets see if the compiler detects it :-

    Output :-

    Code:
    lionaneesh@lionaneesh:~$ gcc first.c -o first
    
    first.c: In function ‘main’:
    
    first.c:6:1: error: expected declaration or statement at end of input
    
    lionaneesh@lionaneesh:~$ 
    
    The Middle End

    The middle end is where the optimisation takes place , It involves removing of useless code , Adding constant values and realocation of computation.

    The Back End

    The code from the previous 2 ends finally comes to back end where it is translated to Low Level Assembly , Critical Changes like variables to registers , Intructions to specific Assembly instructions takes place in this end.

    I hope you liked the article ,Stay tuned for more
     
  2. Jacobhine

    Jacobhine New Member

    Joined:
    Aug 8, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Really nice post, clear all my doubts of C compiler
     
  3. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    My Pleasure!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice