Malcolm McLean <> writes:
> On May 30, 10:05Â*pm, Keith Thompson <ks...@mib.org> wrote:
>> Chad <cdal...@gmail.com> writes:
>> Unless you're dealing with very
>> low-level details, you don't need to know about how the hardware
>> stack works to understand how a C program works.
>>
> Most people need a concrete picture in their mind to understand
> something. Whilst theoretically using abstract definitions like
> "automatic storage duration" gives someone the information required to
> understand how a C program works, in fact it takes most people an
> unacceptably long time to understand something described in those
> terms. A description of a stack pushing variables on and popping them
> off, however, will give most people a good enopugh mental picture.
> Much later you can introduce the idea that some very small or very
> high-level implemetations might not have harware stacks, but only
> after they are already fluent C programmers.
Certainly different people have different ways of understanding
things.
Speaking for myself, it's enough to understand that storage for
called functions is "pushed" when the function is called and "popped"
when it returns (this implies a stack-like data structure but
says nothing about how the storage is allocated). Knowing whether
successive allocations occupy monotonically increasing or decreasing
storage locations is not something I find particularly helpful.
My mental model of the call stack is more like a linked list than
an array.
I can see that others might find the whole thing easier to
understand if they assume a contiguous stack. But IMHO that way
of thinking is dangerously close to treating addresses and integers
as interchangeable. It's also easy to assume that the stack grows
in a particular direction. And, on some unusual platforms, it's
just wrong.
I suggest that trying to think of it more abstractly is worth
the effort. Not only is it closer to what the language actually
specifies, it can help you understand why a contiguous stack is
a good way of implementing it (as well as why it's not the only
possible implementation).
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"