C stack/scope, variable's lifetime after functions ends

Posted by Ranking Stackingblocks on Stack Overflow See other posts from Stack Overflow or by Ranking Stackingblocks
Published on 2010-04-20T06:20:56Z Indexed on 2010/04/20 6:23 UTC
Read the original article Hit count: 445

Filed under:
|
void someFunc()
{
    int stackInt = 4;

    someOtherFunc(&stackInt);
}

Is it the case that stackInt's address space could be reallocated after someFunc ends, making it unsafe to assume that the value passed to someOtherFunc represents the stackInt variable with value 4 that was passed to it? In other words, should I avoid passing stack variables around by address and expecting them to still be alive after the function they were initialised in has ended?

© Stack Overflow or respective owner

Related posts about c

    Related posts about stack