Storage of Variables

e8johan@etek.chalmers.se (Johan Eriksson Thelin)
21 Jan 2000 00:44:53 -0500

          From comp.compilers

Related articles
Storage of Variables e8johan@etek.chalmers.se (2000-01-21)
Re: Storage of Variables torbenm@diku.dk (2000-01-23)
| List of all articles for this month |
From: e8johan@etek.chalmers.se (Johan Eriksson Thelin)
Newsgroups: comp.compilers
Date: 21 Jan 2000 00:44:53 -0500
Organization: Chalmers University of Technology
Keywords: storage, question

    What is the prefered way to store variables? To put them on the
stack (push, pop) together with return addresses and such, or to
mantain a local variable heap with nothing but variables and
parameters on.


    The stack approach seems easier since there are instructions to
manage the stack, but makes it more difficult to remember offsets to
the different variables (long branches, short branches, etc.). A local
heap has the advantage that the offsets are really easy to manage, but
the drawback that it will produce more code (to manage the heap
pointer).


    Which way is best to use, and why?


/Johan
[Most languages put locals on the stack because all of the offset
bookkeeping can be handled at compile time. A common compromise is to
use a frame pointer that's initialized from the stack pointer at the
beginning of each routine, with variables referenced relative to the
frame pointer. That means you don't have to keep track of the stack
depth. -John]













Post a followup to this message

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