i read dat stack clearance can be performed in 2 ways
clearnce by calling function n clearence by called function
whats d difference between d 2?
is dere ny difference in d output produced if performed by dese 2 ways?
pls help me
i read dat stack clearance can be performed in 2 ways
clearnce by calling function n clearence by called function
whats d difference between d 2?
is dere ny difference in d output produced if performed by dese 2 ways?
pls help me
Most of the time, the stack is automatically managed for you. You call a function, the stack pointer moves up; you return from a function, the stack pointer moves down. You allocate an automatic local variable by declaring it, the pointer moves up; the object goes out of scope (like Sly), gets destroyed, and the stack pointer moves down.
You should never have to worry about the stack, unless you toast it with a buffer overrun or something. In which case you have to worry about your code, not its stack.
BTW: on most computers, the stack is never "cleared". The pointer just moves down, leaving whatever value was in that part of the stack untouched. This can be illustrated with the following program:
This program should print 5 twice. Why? set() is called; it allocates a variable, and sets that variable to 5. set() returns. print() is called, allocating a variable on the stack of the same size, and so occupying the same memory as set::x. Therefore, print::x starts out at 5, even though it was never initialized or anything.Code:#include <stdio.h> void print(void) { int x; printf("%d\n", x); } void set(void) { int x = 5; printf("%d\n", x); /* to prevent x from being optimised out */ } int main(void) { set(); print(); return 0; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Quite the opposite. In assembly you have to keep track of every little thing, and be very explicit in what you say -- joey here is being vague and leaving us to fill in some missing letters.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.