The Gateway to Computer Science Excellence
+2 votes
Which of following is correct?

1). Drawback with static allocation is that it does not support recursion.

2). Drawback with stack allocation is that, when function completes its execution it will be popped out from stack..

3). Both are correct

4).None of above
in Compiler Design by Boss (31.4k points) | 243 views

2 Answers

+5 votes
Best answer
1. is correct and recursion can never be done with static allocation.

2. is a bit ambiguous. But assuming a functional language feature, this is also true. In order to return a function, its activation record must be alive even after function run. So, activation record is created on heap and not on stack for these languages.
by Veteran (431k points)
selected by
Give a clear explanation for your answer please. The stack supports for LIFO then the function whenever completed it should pop the function is it right?

2 option seems to be advantageous. It saves memory thus efficiency?

It depends from what perspective we look at- that is why I told "ambiguous" - it won't be asked such in GATE. This is like saying Java is better than C- each has its advantages.

Putting activation record on stack and regaining memory is best for performance and efficiency. But it lacks flexibility in the sense that a function can no longer be returned by another function - a feature needed for functional language. I guess most of you (even me) have not programmed in functional language and hence cannot understand more on that side. If interested you can see Haswell or even lambda functions in C++11.
0 votes
What is ans???

any one explain pllz???
by Boss (15k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,384 answers
105,333 users