Re: Pointers to global and stack variables

henry@spsystems.net (Henry Spencer)
27 Nov 2005 00:37:13 -0500

          From comp.compilers

Related articles
Pointers to global and stack variables shreyas76@gmail.com (shrey) (2005-11-26)
Re: Pointers to global and stack variables henry@spsystems.net (2005-11-27)
Re: Pointers to global and stack variables 148f3wg02@sneakemail.com (Karsten Nyblad) (2005-11-29)
Re: Pointers to global and stack variables alexc@TheWorld.com (Alex Colvin) (2005-11-30)
| List of all articles for this month |

From: henry@spsystems.net (Henry Spencer)
Newsgroups: comp.compilers
Date: 27 Nov 2005 00:37:13 -0500
Organization: SP Systems, Toronto, Canada
References: 05-11-118
Keywords: design
Posted-Date: 27 Nov 2005 00:37:13 EST

  shrey <shreyas76@gmail.com> wrote:
> I am trying to understand what might be a few major and general
>reasons why programmers might have pointers to global and stack data as
>compared to pointers to heap which are essential to building data
>structures...


The most fundamental reason, in some sense, is that many languages
make it awkward or impossible to return multiple values from a
procedure except by passing some variables by reference or
value-result, which is almost always done with pointers to the
variables.


Similarly, it is often desirable to pass large objects by reference to
avoid expensive copying operations, even in cases where there is no intent
to have the procedure alter the objects. (If they're strictly read-only,
this is just an implementation detail, but if aliasing with an output
parameter is possible, then you have to make this explicit because it can
change how programs behave.)


Optimized traversals of arrays also typically involve using pointers
rather than just indexes.


Depending on the language, the pointers for these operations may or may
not be visible to the programmer. You can invent ways to express these
things without introducing general pointers into the language, and treat
the use of pointers to implement them as the compiler's problem. You do
lose some flexibility that way, though.
--
spsystems.net is temporarily off the air; | Henry Spencer
mail to henry at zoo.utoronto.ca instead. | henry@spsystems.net


Post a followup to this message

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