where do the automatic variables go ? - VxWorks

This is a discussion on where do the automatic variables go ? - VxWorks ; In the following code: int i = 5; ---> it goes to .data segment int j; ---> it goes to bss segment int main() { int c; int i = 5; ---> stack int j[5] = new int[5]; ----> heap ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: where do the automatic variables go ?

  1. where do the automatic variables go ?

    In the following code:

    int i = 5; ---> it goes to .data segment
    int j; ---> it goes to bss segment

    int main()
    {
    int c;
    int i = 5; ---> stack
    int j[5] = new int[5]; ----> heap
    c = i*2; ----> goes to .text segment
    }

    My question is : When the object file is created there are text, data
    and bss segments etc...but there is notthing like stack and heap
    segment, what happens to these automatic variables ?

    I hope I am making sense.....



    Siddharth

  2. Re: where do the automatic variables go ?

    sidd wrote:

    >In the following code:
    >
    >int i = 5; ---> it goes to .data segment
    >int j; ---> it goes to bss segment
    >
    >int main()
    >{
    >int c;
    >int i = 5; ---> stack
    >int j[5] = new int[5]; ----> heap
    >c = i*2; ----> goes to .text segment
    >}
    >
    >My question is : When the object file is created there are text, data
    >and bss segments etc...but there is notthing like stack and heap
    >segment, what happens to these automatic variables ?
    >
    >I hope I am making sense.....


    You're making enough sense to figure out that you're asking a question
    about the C programming language rather than a question about VxWorks
    and would therefore be better asked in a group such as comp.lang.c.

    A quick answer, however, is that you are correct there are no stack
    and heap segments. The size and location of the stack and heap are
    instead determined in ways that are often dependent on the target
    architecture, the compiler, and other factors. Standard C uses the
    stack to provide temporary storage for automatic variables.

    --
    ================================================== ======================
    Michael Kesti | "And like, one and one don't make
    | two, one and one make one."
    mrkesti at hotmail dot com | - The Who, Bargain

  3. Re: where do the automatic variables go ?

    On Aug 9, 9:51*pm, "Michael R. Kesti" wrote:
    > sidd wrote:
    > >In the following code:

    >
    > >int i = 5; *---> it goes to .data segment
    > >int j; * * * *---> it goes to bss segment

    >
    > >int main()
    > >{
    > >int c;
    > >int i = 5; ---> stack
    > >int j[5] = new int[5]; ----> heap
    > >c = i*2; ----> goes to .text segment
    > >}

    >
    > >My question is : When the object file is created there are text, data
    > >and bss segments etc...but there is notthing like stack and heap
    > >segment, *what happens to these automatic variables ?

    >
    > >I hope I am making sense.....

    >
    > You're making enough sense to figure out that you're asking a question
    > about the C programming language rather than a question about VxWorks
    > and would therefore be better asked in a group such as comp.lang.c.
    >
    > A quick answer, however, is that you are correct there are no stack
    > and heap segments. *The size and location of the stack and heap are
    > instead determined in ways that are often dependent on the target
    > architecture, the compiler, and other factors. *Standard C uses the
    > stack to provide temporary storage for automatic variables.
    >
    > --
    > ================================================== ======================
    > * * * * * Michael Kesti * * * * * *| *"And like, one and one don't make
    > * * * * * * * * * * * * * * * * * *| * two, one and one make one."
    > * * mrkesti at hotmail dot com * * | * * * * *- The Who, Bargain- Hide quoted text -
    >
    > - Show quoted text -


    I have posted it on comp.lang.c -- Thanks

  4. Re: where do the automatic variables go ?

    On Aug 9, 11:31*pm, sidd wrote:
    > On Aug 9, 9:51*pm, "Michael R. Kesti" wrote:
    >
    >
    >
    >
    >
    > > sidd wrote:
    > > >In the following code:

    >
    > > >int i = 5; *---> it goes to .data segment
    > > >int j; * * * *---> it goes to bss segment

    >
    > > >int main()
    > > >{
    > > >int c;
    > > >int i = 5; ---> stack
    > > >int j[5] = new int[5]; ----> heap
    > > >c = i*2; ----> goes to .text segment
    > > >}

    >
    > > >My question is : When the object file is created there are text, data
    > > >and bss segments etc...but there is notthing like stack and heap
    > > >segment, *what happens to these automatic variables ?

    >
    > > >I hope I am making sense.....

    >
    > > You're making enough sense to figure out that you're asking a question
    > > about the C programming language rather than a question about VxWorks
    > > and would therefore be better asked in a group such as comp.lang.c.

    >
    > > A quick answer, however, is that you are correct there are no stack
    > > and heap segments. *The size and location of the stack and heap are
    > > instead determined in ways that are often dependent on the target
    > > architecture, the compiler, and other factors. *Standard C uses the
    > > stack to provide temporary storage for automatic variables.

    >
    > > --
    > > ================================================== ======================
    > > * * * * * Michael Kesti * * * * * *| *"And like, one and one don't make
    > > * * * * * * * * * * * * * * * * * *| * two, one and one make one."
    > > * * mrkesti at hotmail dot com * * | * * * * *- The Who, Bargain- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > I have posted it on comp.lang.c -- Thanks- Hide quoted text -
    >
    > - Show quoted text -


    The memory for the local variables will be allocated only during that
    function call. It will be allocated in the stack space of the calling
    task. Every task will be having its own memory stack which is
    dynamically allocated during task creation at runtime. Mostly, all the
    unused memory in the RAM will be used as Heap. All the dynamic
    allocations like malloc/calloc will be using Heap.

    As both of them (Stack section / Heap section) are dynamic and
    dependent of target!, these section will be allocated only at runtime.
    So, You cant see this section in your .o file.

    Hope I am right!
    ~Ramsenthil.

+ Reply to Thread