Related articles |
---|
variables in a static method yhu@qualcomm.com (Yale Hu) (1999-07-05) |
Re: variables in a static method rvs@sparc.spb.su (1999-07-06) |
Re: variables in a static method wmm@fastdial.net (1999-07-06) |
From: | Yale Hu <yhu@qualcomm.com> |
Newsgroups: | comp.compilers |
Date: | 5 Jul 1999 13:42:57 -0400 |
Organization: | QUALCOMM, Incorporated; San Diego, CA, USA |
Keywords: | C++, comment |
In C++, a static method of class X is shared by all instances of X. So
the code generated by a compiler for a static method should have only
one copy in memory at run time, and all instances of the class refers
to the address when the method gets called.
If the static method defines some variables (e.g. X::M() { char
v[100]; ...} ), it seems that each call of the method creates a copy
of the variables. I question is how a compiler allocates the memory
for the variables, allocating with objects at the time the objects get
created? with a fixed offset of the object address?
Thanks,
-YH
[The variables are local to the routine, so I imagine that they're allocated
on the stack for the duration of the call, just like any other automatic
variables. C++ stashes data in only three places: in the structure that
represents an instance of the class for normal class members, in static
memory for static and external data, and on the stack for local variables
within a routine. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.