homework4

homework4 - a[i = 5 i = i 1 i = x i = 1 a[1 = 7 a[2 = 3...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 4 CSC 4101, Fall 2011 Due: 15 November 2011 1. (10 pts) Show the run-time stack with all activation record instances, including static and dynamic chains, when execution reaches position 1 in the following skeletal program (in C-style syntax). Assume that the programming language is statically scoped but does not allow functions as return values. void Foo () { void B (); void A (int flag) { void C () { ... A (0); } if (flag) C (); else B (); ... } void B () { void D () { ... // position 1 } ... D (); } A (1); ... } The calling sequence for this program for execution to reach C is: main calls Foo , Foo calls A , A calls C , C calls A , A calls B , and B calls D . 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2. (10 pts) Consider the following program fragment: void test () { int i; int[5] a; void f (int x) {
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a[i] = 5; i = i + 1; i = x; } i = 1; a[1] = 7; a[2] = 3; f (a[i]); // . .. } What are the values of i and a[1] after function f returns if the parameter is passed by i a[1] value copy-in-copy-out reference need 3. (10 pts) Construct a small piece of code in C-style syntax like in the previous question that behaves differently for call-by-name and call-by-need. 4. (10 pts) Explain why an implementation of a functional language such as Scheme or ML requires a garbage collector. Why does a C implementation not require a garbage collector? Which garbage collection mechanism would you choose for a functional language and why? 2...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

homework4 - a[i = 5 i = i 1 i = x i = 1 a[1 = 7 a[2 = 3...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online