ju******@gmail.com wrote:
Roberto Waltman wrote:
>ju******@gmail.com wrote:
>>When I define a static variable, where is the memory allocated for
the static variable?
This is one of the areas were there is no difference between C and
C++. The answers you got when you asked the same question in
comp.lang.c are still valid.
I think for a static variable defined out of any functions, i.e., it
is a global variable, it is located in the data segment of the
program. How about a static variable defined within a function? it is
a local variable. Is it located at the stack?
There is no such thing in C++ as "data segment" or "stack" (except
std::stack, which is a standard container adaptor). There _is_ the
"free store" where dynamic objects are allocated. We know that static
or automatic objects are not allocated in the "free store", but that's
the extent of the *defined* part.
We also know that the storage for _all_ static objects is reserved
at the program start, function-local static objects included. The
storage is also known to be zero-initialised. *Where* that storage
is located is absolutely implementation- and platform-specific.
If you'd like to talk particulars of object storage implementation
("data segment", "stack", etc.), please do it in a relevant newsgroup,
like one for your OS or compiler.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask