stack clearence

This is a discussion on stack clearence within the C Programming forums, part of the General Programming Boards category; i read dat stack clearance can be performed in 2 ways clearnce by calling function n clearence by called function ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    5

    stack clearence

    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

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by joey View Post
    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
    If you can spell "clearance" right, Joey, you can spell "that" and "the", and "these", and "there", right, as well.

    This is a programming forum, not a billboard for dumbed down beyond belief, English.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    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:
    Code:
    #include <stdio.h>
    
    void print(void) {
        int x;
        printf("&#37;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;
    }
    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.
    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.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Adak View Post
    If you can spell "clearance" right, Joey, you can spell "that" and "the", and "these", and "there", right, as well.

    This is a programming forum, not a billboard for dumbed down beyond belief, English.
    Sounds like he'd make a good Assembly programmer though.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    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.

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by dwks View Post
    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.
    I was actually making fun of the cryptic commands in assembly like mov dx, cx... His spelling kind of reminded me of reading assembly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  2. infix evaluation using stack
    By lewissi in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2005, 01:56 AM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 09:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 05:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21