Hi Mark,
>>I think the issue here is to distinguish between something that
>>/logically/ behaves like a stack,
> In what way does the standard /REQUIRE/ the logical behaviour of a
> stack.
Well, in a very obvious way really. Actual parameters and local
variables are accessible during execution of a function; they become
inaccessible during a recursive call as the same formal parameters and
local variables now refer to new, independent variables, which cease to
exist upon return from the secondary call to the same function. I think
you will agree that this behavior is prescribed by the standard.
To me at least, this seems equivalent to viewing the set of parameters
and local variables as a tuple; the ordered list of these tuples
associated with recursive invocations of a function, of which only the
current one is accessible, has all the hallmark properties of a stack of
which only the top-most element is accessible at any given time.
> Thats as opposed to "S Cabot needs an internal mental picture of how
> function calls etc work, and he finds the idea of a stack easy to
> visualise and operate with". No offense intended.
None taken, not even for misspelling my name
> For myself I don't need this mental picture. I think of function
> calls, recurnsion and automatics as involving the computer storing
> different data in various places, and remembering where it is at the
> relevant time.
My main argument in this thread is not whether C prescribes a logical
stack or not; for me that's a useful model (so good, in fact, that I
would be interested to see where this model falls apart), and for you it
isn't. That's A-ok by me.
On the risk of committing speculation, I think you would be hard-pressed
to find a compiler implementor who doesn't use the stack as a very
useful model while implementing a C (or any other) compiler.
What I /would/ like to get to is the phenomenon that a seemingly
standard-compliant program can exhibit undefined behavior. There's a
number of explanations (perhaps there are more):
* the standard does in fact cover this case through a specific limit
exceeded (for example) by my small program, and nobody mentioned
it so far in this thread.
* the standard does in fact cover this case, as it presumes an
idealized machine where certain practical constraints do not
hold (I'd welcome a clear reference).
* the standard does not cover this case.
Presuming for the moment that the third case is what's going on, I think
it is a worthwile exercise to ponder if/how the standard could be
amended in such a way as to cover this case. Stack overflow (perhaps
'resource depletion due to many nested function calls' is a better, but
clumsier term), in my opinion, is a phenomenon that is important enough
to deserve mention in the standard. I would be interested to know if
people disagree with this.
> A bit like me working on something, and using various books from my
> bookshelf. I feel no compulsion to make a "stack" of hte ones I need,
> pushing the most recently used one to the top, and then popping it off
> again when I'm done. I merely pull them off the shelf when needed, and
> put 'em back afterwards, generally in much the same place but a few
> books to the left or right doesn't matter, I'm no Dewey obsessive.
But then, you're not a running C program which, I hope, exhibits a level
of neurotic-obsessive behavior that would make a clinical psychiatrist
dance with joy.
Best regards,
Sidney Cadot