Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Unused Static Stack Varibles

Name: Anonymous 2009-10-31 1:48

Hey /prog/,

In C, are variables located in the stack recycled/freed when they are no longer needed? I suppose that this depends on the compiler, but does anyone know if GCC does this?

To be a little clearer, let's say I have these two translation units...

main.c/.h
settings.c/.h

main() calls the function get_settings() (located in settings.c) which will fill the variables (located in main.c) with data read from a file and then returns.

Since there is no longer any purpose for the staic variables declared in settings.c, are they freed once get_settings() returns?

Name: Anonymous 2009-11-01 3:24

>>40
What don't you understand about that statement?

C:
{
  a = 1;
}
{
  b = 2;
}

//A fictional(a real compiler may remove (dead code elimination)that exact code since it isn't used) compiler may translate it to something like this:
mov edx,1 ; allocs edx to be used for a
mov edx,2 ; a is out of scope, allocs edx to be used for b

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List