Re: How is the concept of scope implemented?

kamal <kamalpr@hp.com>
Tue, 18 Nov 2008 20:45:41 -0800 (PST)

          From comp.compilers

Related articles
[3 earlier articles]
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-14)
Re: How is the concept of scope implemented? liangkun1983@gmail.com (Alex L.K) (2008-11-15)
Re: How is the concept of scope implemented? lkrupp@pssw.com (Louis Krupp) (2008-11-15)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-18)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-18)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-18)
Re: How is the concept of scope implemented? kamalpr@hp.com (kamal) (2008-11-18)
Re: How is the concept of scope implemented? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-11-19)
Re: How is the concept of scope implemented? yangjunpro@gmail.com (yangjunpro: Target locked-->Ruby++) (2008-11-18)
Re: How is the concept of scope implemented? j.vimal@gmail.com (Vimal) (2008-11-19)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-19)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-19)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-19)
[1 later articles]
| List of all articles for this month |

From: kamal <kamalpr@hp.com>
Newsgroups: comp.compilers
Date: Tue, 18 Nov 2008 20:45:41 -0800 (PST)
Organization: Compilers Central
References: 08-11-054
Keywords: symbols
Posted-Date: 19 Nov 2008 19:51:20 EST

On Nov 14, 12:40 pm, "Tony" <t...@my.net> wrote:
> In C++, there is many kinds of scope: global, translation unit, function,
> local (between the curly brackets within a function), class and probably
> more. How is the concept of scope implemented by a compiler for a program?
>
> Tony


For static variables.
The same way as for C -a tree of stacks. The scope in which you are
executing shows the node where you are present in the tree, If a
symbol is not found within a node, you look above (in the enclosing
scope) till you hit the root node.


For member functions/variables,
  there is something called RTTI (run-time type identification) where
the C++ runtime library resolves scope at runtime and enables you to
call the appropriate member function. The instance of class which is
used to call a member function is represented by an implicit pointer
(this) and that is used to access variables when a member function
accesses them.


Hope this answers your question.


regards
-kamal


.



Post a followup to this message

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