GATE / CS ARCHIVE

GATE CSE 2012 / QUESTION 36

Static links in nested procedure activations

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

GATE 2012, Q36 2 marks · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 36, GATE 2012: In a lexically scoped block language, main declares A1 and A2. A1 calls A2. A2 declares A21 and calls A21; A21 calls A1. Main calls A1, producing the live call stack main→A1(first)→A2→A21→A1(second). Which activation-record/access-link diagram is correct? Let M, X, Y, Z, W denote these five activations respectively. Arrows below are access (static) links, and FP denotes the frame pointer.
(A) X→M, Y→X, Z→Y, W→Z; FP=W.
(B) Y→M, Z→Y, W→Z; no access link is drawn for X; FP=W.
(C) Only M,X,Y,Z are drawn: X→M, Y→M, Z→Y; W is absent and FP=X.
(D) X→M, Y→M, Z→Y, W→M; FP=W.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

An access link points to the activation of the lexically enclosing procedure, not generally to the caller. Both A1 activations and A2 are declared directly in Main, so all three point to Main. A21 is declared in A2, so its access link points to that A2 activation. The frame pointer is at the latest (bottom) A1 activation. Option D depicts precisely these static links; caller links instead would form the dynamic call chain.

Check: The second A1 was called by A21, but A1’s declaration remains inside main. Dynamic recursion changes which activation is current, not the lexical parent. Thus its static link skips both A21 and A2, while its dynamic caller link would point to A21.

Original paper, page 9 · Answer key