GATE / CS ARCHIVE

GATE CSE 1999 / QUESTION 15(iii)

Expose copy-restore aliasing

Programming in C · Functions & Parameter Passing · Full GATE CSE 1999 paper

GATE 1999, Q15(iii) Descriptive
Report issue

Functions & Parameter Passing

Question 15(iii), GATE 1999: Determine printed a under call by copy-restore for:
procedure P(x,y,z);
begin y := y+1; z := x+x end;
begin
  a := 2; b := 3;
  P(a+b,a,a);
  print(a)
end.
GFG supplies a:=2, which is missing in GateForum. No copy-back order is specified.
Question 15(iii), GATE 1999: Determine printed a under call by copy-restore for:
procedure P(x,y,z);
begin y := y+1; z := x+x end;
begin
  a := 2; b := 3;
  P(a+b,a,a);
  print(a)
end.
GFG supplies a:=2, which is missing in GateForum. No copy-back order is specified.
Question 15(iii), GATE 1999: Determine printed a under call by copy-restore for:
procedure P(x,y,z);
begin y := y+1; z := x+x end;
begin
  a := 2; b := 3;
  P(a+b,a,a);
  print(a)
end.
GFG supplies a:=2, which is missing in GateForum. No copy-back order is specified.
Tap to enlarge
Answer & solution

Answer: 10 if y restores before z; 3 if z restores before y; no unique output without a convention. (no official key was published)

Copy-in gives independent local values x=5, y=2, z=2. The body ends with x=5, y=3, z=10. Both y and z have the same copy-back destination, caller a, so restoration order matters. Restoring y then z sets a first to 3 and then to 10, printing 10. Restoring z then y sets a first to 10 and finally to 3, printing 3. Thus the given program has no uniquely determined copy-restore result unless the language specifies the order. A left-to-right formal-parameter restoration convention yields 10. As in reference passing, the non-variable actual a+b requires an expression temporary or a rule permitting input-only expressions; strict copy-in/copy-out parameters requiring assignable actuals reject the call. Under the temporary convention restoring unchanged x does not affect a. This is aliasing at copy-back, not aliasing between the local parameter cells.

Original paper, page 8