GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 26(a)

Passing reference and value parameters

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

GATE 1993, Q26(a) Descriptive
Report issue

Runtime Environments & Parameter Passing

Question 26(a), GATE 1993: Procedure P(var x:integer; y:integer) is called as P(a,b). What is pushed on the argument stack for a and b?
Question 26(a), GATE 1993: Procedure P(var x:integer; y:integer) is called as P(a,b). What is pushed on the argument stack for a and b?
Tap to enlarge
Answer & solution

Answer: Address of a for x; current integer value of b for y. (no official key was published)

The var qualifier gives x reference semantics: P must be able to access and modify the caller's actual variable a. Therefore pass a's storage address, not merely its current contents. The unqualified integer y is a value parameter, so evaluate b and push a copy of its current integer value.

After entry, assigning to x changes a because x denotes a through the supplied reference. Assigning to y changes only the callee's copy, leaving b unchanged. Passing the address of b for y would instead implement reference semantics; passing only a's value for x would lose the required alias to the caller's variable.

The question concerns argument payloads, not a complete activation-record layout. Return addresses, saved links and registers may also occupy the stack, but their presence does not change these two payloads. Argument order and stack growth direction depend on the calling convention and are not specified, so no particular push order or numeric offsets should be invented.

Original paper, page 14