Memory Segments Queries

Discussion in 'C' started by kanaks_go4ex, Nov 5, 2008.

Thread Status:
Not open for further replies.
  1. kanaks_go4ex

    kanaks_go4ex New Member

    Joined:
    Jun 11, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    Analyzing the memory layout for my sample program in Linux Environment.

    ----------------------------------
    Code:
    #include<stdio.h>
    
    int test_g = 1; // Data or BSS ? Data section Right ?
    int test_h; // Data or BSS ? BSS section Right ?
    
    static int test_s = 1;
    static int test_q;
    
    
    int func1(bool a ,bool b)
    {
    short temp;
    static int var_temp; // Stack or BSS ?
    return 0;
    
    }
    
    int main(void)
    {
    int m_var = 0; // Will be assigned in Stack section Right ?
    static int main_temp = 0 ; Which section Data or BSS ?
    m_var = func(true,true);// Will be assigned in Stack section Right ?
    
    return m_var;
    
    }
    
    
    help me for the queries added as comments in 'C' Program.
    ------------------------------------


    My Qs Is :

    What are all the sections shared during ,when the function call func1 made from the main?

    Generally every function call has its own stack.Other sections bss , data . text are shared between the multiple process or threads ?.
    will the heap shared ?



    Will the compiler assign the sections during the program compilation itself?
     
    Last edited by a moderator: Nov 6, 2008
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

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