GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 54

Activation records, recursion and escaping closures

Compiler Design · Runtime Environments & Parameter Passing · Full GATE CSE 2008 paper

GATE 2008, Q54 2 marks · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 54, GATE 2008: Which are true? I: a language without globals or nested procedures, but with recursion, can use static storage allocation. II: multilevel access links/displays are needed only for languages with nested procedures. III: recursion cannot use dynamic storage allocation. IV: nesting and recursion require heap allocation and cannot use stack activation records. V: languages allowing a function to return a function cannot use only stack allocation for activation records.

(A) II and V only
(B) I,III,IV only
(C) I,II,V only
(D) II,III,V only
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Under the standard language-runtime assumptions, II and V are true, giving A. I is false: recursive calls can have arbitrarily many simultaneously live instances of local variables, so one statically allocated activation record per procedure is insufficient even without globals or nested procedures.
2. II is true: multilevel static access links/displays serve access to lexically enclosing procedures; without lexical nesting no multilevel environment chain is needed. III is false because dynamic stack allocation supports ordinary recursion.
3. IV is false because nested procedures and recursion alone can use stack activation records with static/dynamic links. V describes a returned nested function that can retain its defining environment after the creator returns: pure stack allocation cannot preserve that environment, so escaping environments need extended lifetime, normally heap allocation or copying.
4. The literal statement V is too broad without that escaping-closure assumption: a function may return a pointer to a global function, or a function with no captured environment, while ordinary activation records remain stack allocated. Thus A is the intended answer under the nested escaping-function interpretation, not a universal consequence of merely returning any function.

Original paper, page 11