Re: Pointers to global and stack variables (Henry Spencer)
27 Nov 2005 00:37:13 -0500

          From comp.compilers

Related articles
Pointers to global and stack variables (shrey) (2005-11-26)
Re: Pointers to global and stack variables (2005-11-27)
Re: Pointers to global and stack variables (Karsten Nyblad) (2005-11-29)
Re: Pointers to global and stack variables (Alex Colvin) (2005-11-30)
| List of all articles for this month |

From: (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 <> 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

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

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.
-- is temporarily off the air; | Henry Spencer
mail to henry at instead. |

Post a followup to this message

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