variable storage

Discussion in 'C Programming' started by kanalkannan, Jan 7, 2008.

  1. kanalkannan

    kanalkannan Guest

    Hi,
    I have heard a question in C data storage i want to know where
    the auto,static and global variables are get stored and what are the
    memory segments like stack heap and its allocation.

    waiting for reply.
    kanalkannan, Jan 7, 2008
    #1
    1. Advertising

  2. kanalkannan

    Ian Collins Guest

    kanalkannan wrote:
    > Hi,
    > I have heard a question in C data storage i want to know where
    > the auto,static and global variables are get stored and what are the
    > memory segments like stack heap and its allocation.
    >

    The answer lies in your compiler documentation, none of the above are
    standardised.

    --
    Ian Collins.
    Ian Collins, Jan 7, 2008
    #2
    1. Advertising

  3. kanalkannan

    santosh Guest

    kanalkannan wrote:

    > Hi,
    > I have heard a question in C data storage i want to know where
    > the auto,static and global variables are get stored and what are the
    > memory segments like stack heap and its allocation.
    >
    > waiting for reply.


    These details are specific to the compiler and it's target system.
    santosh, Jan 7, 2008
    #3
  4. kanalkannan

    Wang Jiaji Guest

    On Jan 7, 3:35 pm, kanalkannan <> wrote:
    > Hi,
    > I have heard a question in C data storage i want to know where
    > the auto,static and global variables are get stored and what are the
    > memory segments like stack heap and its allocation.
    >
    > waiting for reply.


    They're compiler specific and not very important, you can create your
    own segment, with any name you like.
    Wang Jiaji, Jan 7, 2008
    #4
  5. Wang Jiaji <> writes:
    > On Jan 7, 3:35 pm, kanalkannan <> wrote:
    >> Hi,
    >> I have heard a question in C data storage i want to know where
    >> the auto,static and global variables are get stored and what are the
    >> memory segments like stack heap and its allocation.
    >>
    >> waiting for reply.

    >
    > They're compiler specific


    True.
    > and not very important,


    Probably true, though they might be important in some contexts.

    > you can create your
    > own segment, with any name you like.


    Oh? C has no concept of "segments". Any mechanism for creating your
    own would be extremely system-specific.

    --
    Keith Thompson (The_Other_Keith) <>
    [...]
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Jan 7, 2008
    #5
  6. kanalkannan

    Randy Howard Guest

    On Mon, 7 Jan 2008 09:42:10 -0600, Keith Thompson wrote
    (in article <>):

    > Wang Jiaji <> writes:
    >> you can create your
    >> own segment, with any name you like.

    >
    > Oh? C has no concept of "segments". Any mechanism for creating your
    > own would be extremely system-specific.


    int segment; /* this is my segment, there are many like it
    * but this one is mine.
    */




    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
    Randy Howard, Jan 7, 2008
    #6
  7. kanalkannan

    user923005 Guest

    On Jan 6, 11:35 pm, kanalkannan <> wrote:
    > Hi,
    >         I have heard a question in C data storage i want to know where
    > the auto,static and global variables are get stored and what are the
    > memory segments like stack heap and its allocation.


    All auto variables are placed into automatic storage.
    All variables allocated with malloc() or calloc() are placed in
    allocated storage.
    All variables that are static or global have static duration.

    Stack and heap do not appear in the standard. Many compilers place
    automatic storage on a stack. Many compilers place allocated storage
    on a heap. From the C language's perspective, understanding of the
    physical location is not necessary to use the memory. There is no
    imporant reason that all three types of storage could not be in the
    same type of physical structures and general locations.

    If you really want to know where something resides, take the address
    of it (unless it is already an address) and (after casting to void *)
    print the address with a %p format specifier. That will tell you
    where the variable is located. Of course, it could be a symbolic
    address running in a virtual machine, but that's neither here nor
    there. You would get the compiler's view of where the data lives
    exactly in any case.
    user923005, Jan 8, 2008
    #7
    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. Pradeep Kumar C

    Storage of Application Variable

    Pradeep Kumar C, Oct 30, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    452
    Kevin Spencer
    Nov 1, 2004
  2. Patrick Hoffmann
    Replies:
    3
    Views:
    2,812
    Christian Janßen
    Aug 8, 2003
  3. Peter van Merkerk

    static variable and stack storage

    Peter van Merkerk, Aug 25, 2003, in forum: C++
    Replies:
    1
    Views:
    4,994
    Eric Liu
    Aug 26, 2003
  4. ravi_shankar

    default storage class specifier of a variable

    ravi_shankar, Jul 5, 2003, in forum: C Programming
    Replies:
    1
    Views:
    473
    Jack Klein
    Jul 5, 2003
  5. sarathy
    Replies:
    2
    Views:
    649
    sarathy
    Jul 17, 2006
Loading...

Share This Page