In <f7**************************@posting.google.com >
iu*********@yahoo.co.in (anonymous) writes:
Static variables are declared in neither heap nor stack, they are declared
in C source code files. And they are *allocated* whereever the
implementor chooses to, typically neither in heap (the malloc and friends
arena) nor in stack (automatic allocation arena and function call related
data).
But is it not required to allocate static variables in heap, so
that their values are intact even after a function is called more than once?
Then, why the hell would you want to allocate them in a *dynamic* data
structure?
Then generally where are they allocated?.
In a static data structure, usually called the program's data segment.
Depending on how they are initialised, they can be allocated in its
initialised part (that is "mirrored" in the executable file) or in its
"uninitialised" part (that is zero filled by the OS) that occupies no
space in the executable file (only its size and relative address are
stored).
Things are slightly different in the case of freestanding implementations,
where, instead of executable file, the initialised data might be stored
in some kind of non-volatile, read-only memory, before being copied to the
actual read/write memory where it was actually allocated, as part of
the program startup procedure, before main() is actually executed.
Anyway, the program doesn't care where its static data is allocated,
and this is the only thing that matters in the context of this newsgroup.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email:
Da*****@ifh.de