A
asit
We kno that data can be pushed onto the stack or popped 4m it. Can
stack be traversed ??
stack be traversed ??
asit said:We kno that data can be pushed onto the stack or popped 4m it. Can
stack be traversed ??
We kno that data can be pushed onto the stack or popped 4m it.
Can
stack be traversed ??
We kno that data can be pushed onto the stack or popped 4m it. Can
stack be traversed ??
asit said:We kno that data can be pushed onto the stack or popped 4m it. Can
stack be traversed ??
Tor said:What stack does the abstract C machine have?
CBFalconer said:Just in case this is a serious question, none.
jacob said:This is wrong.
When a function is called, the value of the local variables is no
longer active and is preserved until the called function returns.
When the called function returns, the local variables are reactivated.
If this is not a stack, I do not know what a stack is...
A function call is a push into this stack, a function return is
a pop.
santosh said:As K and R themselves note, the function call and return mechanism in C
impose a stack like discipline on local variables, but this feature
need not actually be implemented with a stack (hardware or otherwise).
You could do the same with data structures based on dynamically
allocated memory too (heap), but it would be cumbersome and warranted
only when a stack will not work.
I would guess that no actual implementation of C has ever done it this
way, but the Standard doesn't forbid it and hence does not mandate a
stack.
Richard said:This would still be a "stack" in the algorithmic sense.
This ridiculous "we dont do stack" view is nothing short of silly word
games. And I will continue to think that until someone proves to me that
the variable behaviour you describe is not "stack like" behaviour in C.
It is still a stack IMO.
jacob said:This is wrong.
When a function is called, the value of the local variables is no
longer active and is preserved until the called function returns.
santosh said:As K and R themselves note, the function call and return mechanism in C
impose a stack like discipline on local variables, but this feature
need not actually be implemented with a stack (hardware or otherwise).
You could do the same with data structures based on dynamically
allocated memory too (heap), but it would be cumbersome and warranted
only when a stack will not work.
I would guess that no actual implementation of C has ever done it this
way, but the Standard doesn't forbid it and hence does not mandate a
stack.
jacob navia said:There are things that are self evident except for some people here that
like to confuse beginners when they ask a question.
"There is no stack in C".
The only objective with this answer is to confuse people.
And nobody here (nor the OP) is speaking about a hardware stack. It is
conceptually a stack!
Of course it is a stack. The standard doesn't mandate a stack because
everybody knows what a stack is, and uses a stack. The standard doesn't
write
There are things that are self evident except for some people here that
like to confuse beginners when they ask a question.
"There is no stack in C".
The only objective with this answer is to confuse people.
And nobody here (nor the OP) is speaking about a hardware stack. It is
conceptually a stack!
Flash Gordon said:So we have an example of a C compiler where arithmetic
overflow/underflow is explicitly documented by the compiler as
producing unexpected and unpredictable results!
ravi said:yes stack can be traversed whether it is in static or dynamic memory
allocation
if it is static implementation using arrays then it can be traversed
by simply for loop as in case of arrays
or if it is in dynamic or linked list repesentation it can be
traversed by setting a pointer to the top and then traversing address
of the next pointer until its null
Joe Wright said:No. There is no 'stack', dynamic or otherwise, in C.
jacob said:Of course it is a stack. The standard doesn't mandate a stack because
everybody knows what a stack is, and uses a stack.
"There is no stack in C".
The only objective with this answer is to confuse people.
Mark McIntyre said:jacob navia wrote: [...]"There is no stack in C".
The only objective with this answer is to confuse people.
Bollocks. The objective is to free people from the mistaken belief
that C requires a stack.
Mark said:No. The standard doesn't mandate a stack because C can be, and has been,
implemented on machines which don't use a stack. For example, the
PowerPC annd Sparc chips have so many registers that function parameters
are passed through these.
Note that within computer programming, "the stack" has a specific
meaning, and does not apply to general purpose software stacks
implemented by the programmer.
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.