variables in a static method

Yale Hu <>
5 Jul 1999 13:42:57 -0400

          From comp.compilers

Related articles
variables in a static method (Yale Hu) (1999-07-05)
Re: variables in a static method (1999-07-06)
Re: variables in a static method (1999-07-06)
| List of all articles for this month |

From: Yale Hu <>
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?


[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]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.