GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 1.8

Compiling runtime-sized arrays

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

GATE 1997, Q1.8 1 mark · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 1.8, GATE 1997: A language permits arrays whose sizes are unknown at compile time and requires efficient memory use. Can it be compiled using static allocation, dynamic allocation, or only interpreted?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

The compiler can generate runtime code that evaluates an array’s size, allocates that much storage and records its address and dimensions. Dynamic allocation therefore handles unknown compile-time sizes while avoiding allocation for an arbitrary worst-case bound, giving C. Interpretation is not necessary: compilation can defer particular operations until runtime. Static allocation alone cannot efficiently reserve exactly the required unknown sizes in the general case.

Original paper, page 1