VJ said:
Hi,
I apologize if this question has been asked many times on the group!
I am new to programming,
I know that there are three section in address space- one for code, one
for stack, and the third for Heap.
I just want to know how and where static members are stored in the
address space given to particular program. Is this different from the
way it is done in C?
Thanks in advance,
Next time, try searching the newsgroup and the FAQ first.
I have answered this and other similar questions many times.
The only requirement for static member variables is that
they are stored in memory that has read and write access.
The memory could be on your computer, a harddrive, a
tape drive or a flash memory device, to name a few.
The compiler must ensure that a static member variable
has all the protection and accessibility rights according
to the standard. The standard does not tell _how_ to
do this.
The only time I really care where a variable is stored
is when I am working on an embedded system. I don't
want non-constant variables stored in ROM. I also
have to make sure that there is enough memory for
all of the variables, including temporary ones
(ones with short duration).
If the compiler wants to use stacks, heaps, linked
lists or other structures, it can. I don't care.
I'm more interested in making my program work
correctly than where the compiler places variables.
If my program is not working correctly, there is
no use bothering with optimization or worring about
where the compiler places the variables. [1]
----
1. There have been times when a piece of hardware
was stomping on the variables or when the variables
needed to be aligned and weren't. This is when
I need to know where the variable is stored.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library