GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 2.16

Termination of recursive macro expansion

Compiler Design · Compiler Phases, Linking & Loading · Full GATE CSE 1996 paper

GATE 1996, Q2.16 2 marks · MCQ
Not in GATE 2027 syllabusReport issue

Compiler Phases, Linking & Loading

Question 2.16, GATE 1996: Macro M1 recursively invokes M1(X+1) when X=0, otherwise emits WORD X. M2 instead recursively invokes M2(X) when X=0. Which can recurse indefinitely?
Question 2.16, GATE 1996: Macro M1 recursively invokes M1(X+1) when X=0, otherwise emits WORD X. M2 instead recursively invokes M2(X) when X=0. Which can recurse indefinitely?
Tap to enlarge
Your answer
Answer & solution

Answer: A: (ii) only (no official key was published)

For M1 invoked with X=0, the recursive call receives 1. Its condition is then false, so it emits WORD 1 and stops. For any nonzero initial value it stops immediately. M2 invoked with X=0 calls itself with the same argument, so the condition never changes and expansion repeats indefinitely. Thus only the second definition has the nontermination problem, option A. This reasoning uses expansion-time integer parameter evaluation; the recursion is in the macro processor, not a runtime subroutine.

Original paper, page 5