1 1 vote The drawback with stack storage allocation is when the function completes its execution its result cannot be used some point of time later. Can you please explain this briefly? Compiler Design compiler-design static-allocation + – MIRIYALA JEEVAN KUMA 1.1k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply MiNiPanda commented Jan 21, 2018 reply Follow flag When the 1st function that is the main function is called, then it gets pushed onto the stack..suppose you call fun1() from main then fun1() gets pushed over the main function in the stack. If fun1() calls another function fun2() then that also gets pushed on the top of fun1() and so on. So the view of stack from top to bottom is fun2() fun1() main() Now let fun2() has a local variable x. X gets space in the same stack space allocated for fun2(). When fun2() returns some value to fun1() it means fun2()'s task is over and it is no more required. So it gets popped out from stack. Now the stack view from top to bottom is Fun1() main() Now note that the variable x of fun2() has also gone away along with the fun2() because it was residing inside it. At this moment if you try to access the variable x, it will give error because it's existence in the program is no more. 1 1 replyShare Registered user 48 commented Dec 9, 2018 reply Follow flag It says result of the function cannot be used later, that need not infer to all the stack data right? Just the result of the function, which can be returned to the calling function. 0 0 replyShare Please log in or register to add a comment.
0 0 votes Modern imperative programming languages typically have local variables. – Created upon entry to function. – Destroyed when function returns. When a function is called activation record is created, which is destroyed upon exit. So we cannot use the data at later point of time. Good read: https://www.cs.princeton.edu/courses/archive/spring03/cs320/notes/7-1.pdf smsubham answered Mar 20, 2020 smsubham comment Share Follow 0 reply Please log in or register to add a comment.