![]() It might work most of the time, but just once the wrong input will cause it to go in that circle forever until the computer recognizes that the stack is overblown. Many programmers make this mistake by calling function A that then calls function B, that then calls function C, that then calls function A. who calls function 8 who calls function 9, but function 9 overwrites memory outside the stack. In embedded systems you might only have 256 bytes for the stack, and if each function takes up 32 bytes then you can only have function calls 8 deep - function 1 calls function 2 who calls function 3 who calls function 4. ![]() Stack overflowĪ stack overflow is when you've used up more memory for the stack than your program was supposed to use. When it's done, it frees up the local variable stack space it used, then returns to the previous function. The function you call might use up more stack for its own local variables. When you call a function in your code, the next instruction after the function call is stored on the stack, and any storage space that might be overwritten by the function call. Last in, first out (LIFO) means that the last thing you put in is always the first thing you get back out - if you push 2 items on the stack, 'A' and then 'B', then the first thing you pop off the stack will be 'B', and the next thing is 'A'. A stack, in this context, is the last in, first out buffer you place data while your program runs.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |