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 15:46

>>21
I don't have much experience in C
It shows

This seems wrong. Why would they be stored in the executable if the values are not necessarily known at compile time?
The value isn't stored in the executable, but space is reserved for the value.
if the size of the object changes
You recompile
if your global variable refers to a dynamic array?
The it would be a pointer which always talks 1 word of memory and the dynamic array would be on the heap


--
~This post has not been fact checked due to laziness, and if it's wrong then correct me and stop whining

1. The values aren't stored in the executable, but instead space would be reserved.
2. If a static object changed you would need to recompile it anyway
3.

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