C compiler internals

Discussion in 'C Programming' started by Guru Jois, May 27, 2007.

  1. Guru Jois

    Guru Jois Guest

    Hai,

    Can I get some docs or links to learn the C compiler internals
    from basic to advanced. It must contains good documentation of how
    compilers allocates memory to variables.

    Bye
    Guru Jois
     
    Guru Jois, May 27, 2007
    #1
    1. Advertising

  2. On Sun, 27 May 2007 04:52:52 -0700, Guru Jois wrote:

    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.
    >
    > Bye
    > Guru Jois


    There are a lot of different C compilers out there and some of them are
    closed source. I don't think the MSVC compiler has a lot of in-depth
    documentation on how it works internally.

    Take a look at the following link for some information about the GCC
    compiler:
    http://en.wikibooks.org/wiki/Category:GNU_C_Compiler_Internals

    Hope it helps a bit.

    Regards,
    Jensen
     
    Jensen Somers, May 27, 2007
    #2
    1. Advertising

  3. Guru Jois

    Chris Dollin Guest

    Guru Jois wrote:

    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.


    Why?

    I mean, what problem do you hope to solve with this information?

    Compilers allocate memory -- and registers -- to variables in
    ways that will make the code faster, or smaller, or the compiler
    easier to write, or faster, or smaller; the tradeoffs differ
    even between compilers for the same architecture and can often
    be controlled by command-line switches; what are you going to
    do with the answer?

    --
    Interpreting Hedgehog
    "We did not have time to find out everything we wanted to know."
    - James Blish, /A Clash of Cymbals/
     
    Chris Dollin, May 27, 2007
    #3
  4. "Guru Jois" <> wrote in message
    news:...
    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.


    read books on compiler design maybe, although that has nothing to with C
    anymore
     
    Serve Laurijssen, May 27, 2007
    #4
  5. Guru Jois

    jacob navia Guest

    Guru Jois wrote:
    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.
    >
    > Bye
    > Guru Jois
    >

    Hi guru

    How lcc-win32 allocates memory to variables
    -------------------------------------------

    For lcc-win32 there are several types of variables:
    1) File scope variables, that are allocated in the initialized variables
    section of the executable. For example:
    int table[] = {1,2,3,4,5,6};
    Lcc-win32 will reserve space in the data section for six 32 bit
    numbers and initialize that to the binary values given.
    Each object code file (.obj) can contain contributions to this
    segment. The linker combines them all into a single segment.
    2) File scope variables without any initial values. For example:
    int table[6];
    Lcc-win32 will reserve space for 6 32 bit numbers in the
    uninitialized variable section (bss) and the value of them will be
    set to zero when the system loads the program into memory.
    3) Local variables.
    They are allocated into a memory block reserved for temporary
    storage. This is normally the stack segment. At entry of a function,
    its activation record will be built, and the stack will be adjusted
    to contain space for all local variables of the function. This
    storage will be reclaimed when the function exits.

    4) Variable length automatic variables
    This variables will be allocated in the stack in a similar way as
    (3) but they are not part of the activation frame since the
    activation frame is fixed length, and this variables are variable
    length. Example:
    int fn(int n)
    { int table[n]; // <<<--- variable length array (VLA)
    }
     
    jacob navia, May 27, 2007
    #5
  6. Guru Jois

    jacob navia Guest

    Guru Jois wrote:
    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.
    >
    > Bye
    > Guru Jois
    >

    Hi guru

    How lcc-win32 allocates memory to variables
    -------------------------------------------

    For lcc-win32 there are several types of variables:
    1) File scope variables, that are allocated in the initialized variables
    section of the executable. For example:
    int table[] = {1,2,3,4,5,6};
    Lcc-win32 will reserve space in the data section for six 32 bit
    numbers and initialize that to the binary values given.
    Each object code file (.obj) can contain contributions to this
    segment. The linker combines them all into a single segment.
    2) File scope variables without any initial values. For example:
    int table[6];
    Lcc-win32 will reserve space for 6 32 bit numbers in the
    uninitialized variable section (bss) and the value of them will be
    set to zero when the system loads the program into memory.
    3) Local variables.
    They are allocated into a memory block reserved for temporary
    storage. This is normally the stack segment. At entry of a function,
    its activation record will be built, and the stack will be adjusted
    to contain space for all local variables of the function. This
    storage will be reclaimed when the function exits.

    4) Variable length automatic variables
    This variables will be allocated in the stack in a similar way as
    (3) but they are not part of the activation frame since the
    activation frame is fixed length, and this variables are variable
    length. Example:
    int fn(int n)
    { int table[n]; // <<<--- variable length array (VLA)
    }
     
    jacob navia, May 27, 2007
    #6
  7. Guru Jois

    jacob navia Guest

    Guru Jois wrote:
    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.
    >
    > Bye
    > Guru Jois
    >

    Hi guru

    How lcc-win32 allocates memory to variables
    -------------------------------------------

    For lcc-win32 there are several types of variables:
    1) File scope variables, that are allocated in the initialized variables
    section of the executable. For example:
    int table[] = {1,2,3,4,5,6};
    Lcc-win32 will reserve space in the data section for six 32 bit
    numbers and initialize that to the binary values given.
    Each object code file (.obj) can contain contributions to this
    segment. The linker combines them all into a single segment.
    2) File scope variables without any initial values. For example:
    int table[6];
    Lcc-win32 will reserve space for 6 32 bit numbers in the
    uninitialized variable section (bss) and the value of them will be
    set to zero when the system loads the program into memory.
    3) Local variables.
    They are allocated into a memory block reserved for temporary
    storage. This is normally the stack segment. At entry of a function,
    its activation record will be built, and the stack will be adjusted
    to contain space for all local variables of the function. This
    storage will be reclaimed when the function exits.

    4) Variable length automatic variables
    This variables will be allocated in the stack in a similar way as
    (3) but they are not part of the activation frame since the
    activation frame is fixed length, and this variables are variable
    length. Example:
    int fn(int n)
    { int table[n]; // <<<--- variable length array (VLA)
    }
     
    jacob navia, May 27, 2007
    #7
  8. Guru Jois

    jacob navia Guest

    There is a bug in the thunderbird client apparently...
    It sent the message three times

    Sorry about this

    jacob
     
    jacob navia, May 27, 2007
    #8
  9. Guru Jois

    Tor Rustad Guest

    Guru Jois wrote:
    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.



    Try, comp.compilers and check their FAQ.


    --
    Tor <torust [at] online [dot] no>
     
    Tor Rustad, May 27, 2007
    #9
  10. On 27 May 2007 04:52:52 -0700, Guru Jois <> wrote:

    >Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    >from basic to advanced. It must contains good documentation of how
    >compilers allocates memory to variables.
    >


    Your posts indicate you are a relative newcomer to C and programming.
    It is much too early for you to be jumping into a topic this complex.

    Why do you care how one particular compiler allocates variables? It
    may have nothing to do with how your compiler does so. It may change
    completely in the next version of the compiler.

    At this stage in your development, you should not be writing code that
    depends on a particular allocation technique. Concentrate on the
    portable features of the standard language, which is the area this
    newsgroup deals with.


    Remove del for email
     
    Barry Schwarz, May 27, 2007
    #10
  11. In article <>,
    Guru Jois <> wrote:
    >Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    >from basic to advanced. It must contains good documentation of how
    >compilers allocates memory to variables.


    Take a look at the Dragon Book.

    If that doesn't tell you what you're looking for, you could always
    try Knuth.


    dave

    --
    Dave Vandervies

    Where should I turn in my certificate of infallibility?
    --CBFalconer in comp.lang.c
     
    Dave Vandervies, May 27, 2007
    #11
  12. "Guru Jois" <> wrote in message
    news:...
    > Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    > from basic to advanced. It must contains good documentation of how
    > compilers allocates memory to variables.
    >

    If want the very basics about how to get into the compiler construction
    game, read my book MiniBasic - how to write a script interpreter. It is an
    interpreted rather than a compiled language, but the principles of variable
    usage are similar, however interpreters are easier to write and understand
    than compilers. It is only $2.50.

    If you already know how to write a Basic, try the dragon book by Aho, Sethi
    and Ullman. This is a much more advanced text.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
     
    Malcolm McLean, May 28, 2007
    #12
  13. Guru Jois

    Guru Jois Guest

    On May 27, 11:46 pm, Barry Schwarz <> wrote:
    > On 27 May 2007 04:52:52 -0700, Guru Jois <> wrote:
    >
    > >Hai,

    >
    > > Can I get some docs or links to learn the C compiler internals
    > >from basic to advanced. It must contains good documentation of how
    > >compilers allocates memory to variables.

    >
    > Your posts indicate you are a relative newcomer to C and programming.
    > It is much too early for you to be jumping into a topic this complex.
    >
    > Why do you care how one particular compiler allocates variables? It
    > may have nothing to do with how your compiler does so. It may change
    > completely in the next version of the compiler.
    >
    > At this stage in your development, you should not be writing code that
    > depends on a particular allocation technique. Concentrate on the
    > portable features of the standard language, which is the area this
    > newsgroup deals with.
    >
    > Remove del for email


    Yaeh, I am new to C, but I expect questions about compiler activities
    in interviews. So I need docs.
    Bye
    Guru
     
    Guru Jois, May 28, 2007
    #13
  14. Guru Jois

    Chris Hills Guest

    In article <>, Guru
    Jois <> writes
    >Hai,
    >
    > Can I get some docs or links to learn the C compiler internals
    >from basic to advanced. It must contains good documentation of how
    >compilers allocates memory to variables.


    Hi,

    Compilers are in two parts the front end parser and the target specific
    back end. Where the variables are put and how the memory is allocated
    will depend on the target which is handled in the back end. It won't be
    the same for an 8061 as a 68000 MCU. Some turn out assembler and some
    object code.

    I can send you a PDF book on compiler design but no book on compiler
    design goes from basic to advanced. They go from advanced to very
    advanced.

    Then you have the assembler and linker do contend with

    also books on compiler design are standard technology. Most commercial
    compilers use many proprietary tricks and techniques.

    The best place to start is probably GCC. You get the source and a lot of
    people know how it works internally.

    I would suggest that the way you have asked the question indicates that
    you probably do not have the experience to delve into compiler design
    just yet unless it is just for interest. Though I expect you will find
    it very heavy going..
    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, May 28, 2007
    #14
  15. Guru Jois

    Chris Hills Guest

    In article <>, Guru
    Jois <> writes
    >On May 27, 11:46 pm, Barry Schwarz <> wrote:
    >> On 27 May 2007 04:52:52 -0700, Guru Jois <> wrote:
    >>
    >> >Hai,

    >>
    >> > Can I get some docs or links to learn the C compiler internals
    >> >from basic to advanced. It must contains good documentation of how
    >> >compilers allocates memory to variables.

    >>
    >> Your posts indicate you are a relative newcomer to C and programming.
    >> It is much too early for you to be jumping into a topic this complex.
    >>
    >> Why do you care how one particular compiler allocates variables? It
    >> may have nothing to do with how your compiler does so. It may change
    >> completely in the next version of the compiler.
    >>
    >> At this stage in your development, you should not be writing code that
    >> depends on a particular allocation technique. Concentrate on the
    >> portable features of the standard language, which is the area this
    >> newsgroup deals with.
    >>
    >> Remove del for email

    >
    >Yaeh, I am new to C, but I expect questions about compiler activities
    >in interviews. So I need docs.
    >Bye
    >Guru
    >


    You will not get questions about compiler internals at interviews. If
    you do you are applying for the wrong job.

    What sort of jobs are you applying for?

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, May 28, 2007
    #15
  16. Guru Jois

    Chris Hills Guest

    In article <>, Guru
    Jois <> writes
    >On May 27, 11:46 pm, Barry Schwarz <> wrote:
    >> On 27 May 2007 04:52:52 -0700, Guru Jois <> wrote:
    >>
    >> >Hai,

    >>
    >> > Can I get some docs or links to learn the C compiler internals
    >> >from basic to advanced. It must contains good documentation of how
    >> >compilers allocates memory to variables.

    >>
    >> Your posts indicate you are a relative newcomer to C and programming.
    >> It is much too early for you to be jumping into a topic this complex.
    >>
    >> Why do you care how one particular compiler allocates variables? It
    >> may have nothing to do with how your compiler does so. It may change
    >> completely in the next version of the compiler.
    >>
    >> At this stage in your development, you should not be writing code that
    >> depends on a particular allocation technique. Concentrate on the
    >> portable features of the standard language, which is the area this
    >> newsgroup deals with.
    >>
    >> Remove del for email

    >
    >Yaeh, I am new to C,


    The missing lines are:-

    "I am Master of Computer Application graduate and currently studying
    "Advanced C and Unix" course in Uttara, Bangalore, India."

    >but I expect questions about compiler activities
    >in interviews. So I need docs.
    >Bye
    >Guru
    >


    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, May 28, 2007
    #16
  17. Guru Jois

    David Wade Guest

    "Guru Jois" <> wrote in message
    news:...
    > On May 27, 11:46 pm, Barry Schwarz <> wrote:
    > > On 27 May 2007 04:52:52 -0700, Guru Jois <> wrote:
    > >
    > > >Hai,

    > >
    > > > Can I get some docs or links to learn the C compiler internals
    > > >from basic to advanced. It must contains good documentation of how
    > > >compilers allocates memory to variables.

    > >
    > > Your posts indicate you are a relative newcomer to C and programming.
    > > It is much too early for you to be jumping into a topic this complex.
    > >
    > > Why do you care how one particular compiler allocates variables? It
    > > may have nothing to do with how your compiler does so. It may change
    > > completely in the next version of the compiler.
    > >
    > > At this stage in your development, you should not be writing code that
    > > depends on a particular allocation technique. Concentrate on the
    > > portable features of the standard language, which is the area this
    > > newsgroup deals with.
    > >
    > > Remove del for email

    >
    > Yaeh, I am new to C, but I expect questions about compiler activities
    > in interviews. So I need docs.
    > Bye
    > Guru
    >


    If you want to prepare for an interview have a look through the archived
    copy of this newsgroup at groups.google.com. I would start by searching for
    threads that contain "undefined behaviour". Most other documentation
    concentrates on "how to do" something. These topics will help you understand
    why some things don't work, and also how the compiler works...

    I am pretty sure the information in here is more enlightening than any crib
    sheet,,,,
     
    David Wade, May 28, 2007
    #17
  18. "David Wade" <> writes:
    [...]
    > If you want to prepare for an interview have a look through the archived
    > copy of this newsgroup at groups.google.com. I would start by searching for
    > threads that contain "undefined behaviour". Most other documentation
    > concentrates on "how to do" something. These topics will help you understand
    > why some things don't work, and also how the compiler works...


    You may need to search for both "undefined behaviour" and "undefined
    behavior" (UK vs. US spelling); I'm not sure whether Google is smart
    enough to translate automatically. It's sometimes also referred to as
    "UB".

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, May 28, 2007
    #18
  19. In article <>,
    Keith Thompson <> wrote:
    >"David Wade" <> writes:


    >> If you want to prepare for an interview have a look through the archived
    >> copy of this newsgroup at groups.google.com. I would start by searching for
    >> threads that contain "undefined behaviour".


    >You may need to search for both "undefined behaviour" and "undefined
    >behavior" (UK vs. US spelling); I'm not sure whether Google is smart
    >enough to translate automatically. It's sometimes also referred to as
    >"UB".


    Search also for nasal and demons (or daemons) ;-)
    --
    Programming is what happens while you're busy making other plans.
     
    Walter Roberson, May 28, 2007
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abhishek Srivastava

    Good book on the asp.net internals?

    Abhishek Srivastava, Apr 21, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    638
    Alvin Bruney [MVP]
    Apr 21, 2004
  2. Jobs Gooogle
    Replies:
    2
    Views:
    488
    Patricia Shanahan
    May 11, 2007
  3. Jobs Gooogle
    Replies:
    1
    Views:
    326
    Victor Bazarov
    May 10, 2007
  4. Jobs Gooogle

    .Net VC++ Java C++ Windows Internals Unix Internals

    Jobs Gooogle, May 10, 2007, in forum: C Programming
    Replies:
    0
    Views:
    371
    Jobs Gooogle
    May 10, 2007
  5. Jobs Gooogle
    Replies:
    0
    Views:
    132
    Jobs Gooogle
    May 10, 2007
Loading...

Share This Page