On Feb 7, 9:46 am, "santosh" <santosh....@gmail.comwrote:
The words "stack" and "heap" occur nowhere in the C standard. It's
(too) common to refer to the area used to allocate automatic objects
as the "stack", but I think most of us agree that this is misleading
and incorrect.
Can a perverse but conforming implementation use the "heap" for
automatic objects. As long as their properties, as dictated by the
standard, are honoured, I don't see why they should be allocated from
a stack.
IMO, stack suits the requirement of auto variables at best. As soon a
leaf function is called from parent function, stack is used to store
the status of registers, passing arguments, etc and this scope is
defined till the control stays in leaf function. Similar is the case
with auto/local variables of leaf function. Scope is defined till the
control is in leaf function.
You have to free (to tell system that you can re-write it) "Heap"
every time, you use it for local variable.
The word "stack", in this context, implies a
CPU-specific region of memory that grows linearly in one direction,
controlled by a "stack pointer" that is typically (but not always) a
dedicated CPU register.
I may be wrong, but it was my impression that a stack is simply a LIFO
data structure. It doesn't have to have any specific hardware support.
On stackless architectures, a LIFO may have to be simulated by the C
implementation, for auto objects.
It makes life easier. Simply one HW (may/maynot be memroy mapped)
stack pointer is required to refer it across all functions. (when you
are using single stack implementation)
Yes. It curious why so many students of C are bursting to know where C
objects are stored. I would've thought that an assembly language or
machine architecture course would be the proper place to recieve such
information.
I think, There is misnomer in C. C storage classes. I don't understand
why "storage" word is required when it just defines the life of
variable.
-Nishu