Recursion elimination

  • Thread starter Lorenzo Villari
  • Start date
D

Dave Thompson

Actually in standard Pascal you can't form a pointer to a local
variable, only to allocated aka heap space, although it is a common(?)
extension. And yes, it is the equivalent of Undefined Behavior (not
required to be diagnosed, and AFAIK typically not diagnosed) to
indirect through a pointer to either allocated space which has been
dispose'd or a (local) variable which has gone out of scope.
A-aga... doesn't Pascal have pointers to scalars (integers etc.) just
like C does? What happens if a Pascal function returns a pointer
pointing to an integer outside of scope, and then the calling procedure
or function indirects through that pointer?

Pascal has pointers to all data types, both scalar and composite
(arrays, records, etc.), but not to functions -- or procedures, which
are classified separate in Pascal, as in Ada and (the equivalent) in
Fortran; there is no standard Pascal term that covers both, but both
Fortan and Ada use subprogram, so I will. Since you can't declare a
pointer to subprogram, you can't return one or store it explicitly.

What you can have, as Chuck indicates, is in effect a reference -- a
subprogram parameter which is itself of subprogram "type", but using a
special syntax, not a nameable type, and is called with an actual
(necessarily named) subprogram of appropriate type, which is then used
(called) where the parameter is used. But parameter passing only
works downward (to inner nesting) so it cannot reach a point where the
outer activations needed by the actual subprogram are gone.

In Ada, by contrast, you can have access (their pointer) to
subprogram, as you can to data, but you can't have any access
variable, or even the access type, at a nesting level lower (that is,
outer) than the variables or subprograms you use it to point to --
normally; you can override this for variables with Unchecked_Access,
and for subprograms using Unchecked_Conversion or in GNAT
Unrestricted_Access, in which case you are responsible for the
possibly bogus and undiagnosed results. And for "normal" accesses
that point to allocated/heap space Ada discourages *any* freeing
(Unchecked_Deallocation) which evades the issue of stale pointers.

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top