From: glen herrmannsfeldt on
In comp.arch.fpga Joe Pfeiffer <pfeiffer(a)cs.nmsu.edu> wrote:
(snip)

> You forgot to mention local variables are in the activation record.

> When I was an undergrad I spent some time programming FORTRAN on a
> Harris /6 (I think it was a /6 -- there's something nagging at the back
> of my mind that says it may have been a /7). Anyway, reading the manual
> I discovered that return addresses were stacked, and immediately jumped to
> the conclusion that it could do recursion. It turned out that local
> variables were static... which meant I spent a *long* time figuring out
> why my program was producing completely nonsensical results.

I did it once on the PDP-10. Fortran kept the return address on
the stack, but variables were static. I made local variables arrays
with another variable to increment/decrement with recursion depth.
That was for testing only, I didn't try it for any real problem.

The OS/360 compilers keep the return address in static storage.

> As Al Stewart once sang, "I was jumping to conclusions, and one of them
> jumped back."

-- glen
From: Eric Chomko on
On Feb 24, 6:20 pm, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote:
> On 24/02/2010 19:31, in article
> d902c75e-e33a-4281-a796-7c56c3276...(a)o16g2000prh.googlegroups.com, "Eric
>
>
>
> Chomko" <pne.cho...(a)comcast.net> wrote:
> > On Feb 23, 2:07 pm, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote:
> >> On 23/02/2010 17:52, in article
> >> 3ec03225-3a0f-4bcd-9db1-51201d1b3...(a)w12g2000vbj.googlegroups.com, "Eric
>
> >> Chomko" <pne.cho...(a)comcast.net> wrote:
> >>> But an ALGOL "activation record" (stack frame) had a lot more than
> >>> that. As I recall, they copied a lot more just pointers and parameter
> >>> values.
>
> >> Just the usual red tape: return address, frame pointer of caller; and either
> >> a static pointer or some housekeeping for 'display' registers (if used) to
> >> access non-locals. But bear in mind that in decent languages arrays are
> >> storable values, so a value array parameter gets copied in toto, unlike C.
>
> > Are you saying that C doesn't implement true recursion? I have only
> > used recursion in college and not with C. ALGOL, SIMPL-T and LISP were
> > the only languages I used to write recursive algorithms.
>
> No. I'm at a loss as to how you could put that interpretation on it.

Perhaps I misunderstood your reference, "unlike C". As I recall the
difference between a global and local variable in a block-structured
language is that a global is statically stored like all FORTRAN IV
variables. And locals get put onto the stack with each call to the
function and are dynamically allocated. It is this last aspect that
allows recursion to occur other than allowing a function to call
itself.

>
> I'm saying that array parameters in C are not called by value, but they are
> in Algol 60 and cognate languages, requiring more stack space than C does..

Doesn't a C stack frame contain a lot less than an ALGOL activation
record other than just parameter information?

From: Eric Chomko on
On Feb 24, 6:50 pm, Joe Pfeiffer <pfeif...(a)cs.nmsu.edu> wrote:
> Eric Chomko <pne.cho...(a)comcast.net> writes:
> > On Feb 23, 2:07 pm, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote:
> >> On 23/02/2010 17:52, in article
> >> 3ec03225-3a0f-4bcd-9db1-51201d1b3...(a)w12g2000vbj.googlegroups.com, "Eric
>
> >> Chomko" <pne.cho...(a)comcast.net> wrote:
> >> > But an ALGOL "activation record" (stack frame) had a lot more than
> >> > that. As I recall, they copied a lot more just pointers and parameter
> >> > values.
>
> >> Just the usual red tape: return address, frame pointer of caller; and either
> >> a static pointer or some housekeeping for 'display' registers (if used) to
> >> access non-locals. But bear in mind that in decent languages arrays are
> >> storable values, so a value array parameter gets copied in toto, unlike C.
>
> > Are you saying that C doesn't implement true recursion? I have only
> > used recursion in college and not with C. ALGOL, SIMPL-T and LISP were
> > the only languages I used to write recursive algorithms.
>
> Yes, C does recursion.  Local variables are also on the stack.

I figured it did, but the "unlike C" comment above through me for a
loop! :)
From: Michael Wojcik on
(see below) wrote:
>
> Just the usual red tape: return address, frame pointer of caller; and either
> a static pointer or some housekeeping for 'display' registers (if used) to
> access non-locals. But bear in mind that in decent languages arrays are
> storable values, so a value array parameter gets copied in toto, unlike C.

It will be in C if the array is wrapped in a struct. Letting array
parameters decay to pointers was a feature of early C that couldn't be
changed for historical reasons, but when the standardization committee
added support for struct parameters, they made them first-class.

struct (and not the misnamed "typedef") is C's mechanism for creating
new types and ADTs, so if you want a pass-by-value array in C, the
correct thing to do is to put it in a struct.

This is not to say that C's parameter passing doesn't still have a
number of infelicities. Exposing the use of pointers to implement
pass-by-reference (which C lacks, strictly speaking) has some
advantages, but it has led to great confusion over matters like the
const and restrict qualifiers.

--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University
From: Scott Lurndal on
Joe Pfeiffer <pfeiffer(a)cs.nmsu.edu> writes:
>Eric Chomko <pne.chomko(a)comcast.net> writes:
>
>> On Feb 23, 2:07�pm, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote:
>>> On 23/02/2010 17:52, in article
>>> 3ec03225-3a0f-4bcd-9db1-51201d1b3...(a)w12g2000vbj.googlegroups.com, "Eric
>>>
>>> Chomko" <pne.cho...(a)comcast.net> wrote:
>>> > But an ALGOL "activation record" (stack frame) had a lot more than
>>> > that. As I recall, they copied a lot more just pointers and parameter
>>> > values.
>>>
>>> Just the usual red tape: return address, frame pointer of caller; and either
>>> a static pointer or some housekeeping for 'display' registers (if used) to
>>> access non-locals. But bear in mind that in decent languages arrays are
>>> storable values, so a value array parameter gets copied in toto, unlike C.
>>>
>>
>> Are you saying that C doesn't implement true recursion? I have only
>> used recursion in college and not with C. ALGOL, SIMPL-T and LISP were
>> the only languages I used to write recursive algorithms.
>
>Yes, C does recursion. Local variables are also on the stack.

More precisely, variables with non-file scope declared implicitly
or explicitly automatic, are on the stack. Variables with non-file
scope can still be declared static, if desired.


int
f(int a, int b)
{
int c; /* Implicit auto: on stack */
auto int d; /* Explicit auto: on stack */
static int e; /* Explicit static: in data section */

return a + b;
}