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-10-31 4:31

>>7,11
register allocation bullshit
Is this even related to this thread or is it just your way of saying "I haven't read SICP"? Registers have no fucking relation to the discussion.

>>8
File-local variables (i.e. variables in the global scrope but declared static) and global variables are just stored as part of the executable which is mapped into the process's address space by the linker.
One of the less retarded replies in this thread.


OP, use locals instead of statics. Why would you even need statics in your settings code if you call it just once? If the problem is that multiple functions need to access the data, then make it a struct and pass it around via pointer. Then you can free it when you're done.

Why aren't your variables in get_settings() in the first place?

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