Re: variables in a static method (Roman Shaposhnick)
6 Jul 1999 12:00:38 -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: (Roman Shaposhnick)
Newsgroups: comp.compilers
Date: 6 Jul 1999 12:00:38 -0400
Organization: St.Petersburg University
References: 99-07-017
Keywords: C++

On 5 Jul 1999 13:42:57 -0400, Yale Hu wrote:

>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.

It seems to be a little bit misunderstanding here. AFAIK, all C++
compilers generate exactly one copy of each method and supplie correct
'this' pointer every time the method is 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,

Just the same way it happens with an ordinary function. In your case
v[100] will be allocated on a stack.


Post a followup to this message

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