HW 10/24 Solution Scott: 3.1, 3.5, 3.6, 3.7, 3.11, 3.14 3.1 Decision Binding time Number of built-in functions design Variable declaration that corresponds compile-time to a particular variable reference (i.e., use) Maximum length allowed for a constant design or compiler implementation character string The referencing environment for a subroutine deep vs shallow binding: design that is passed as a parameter the actual environment: execution The address of a particular library routine link Total amount of space occupied by code space for code: compile time and data space for static and globals: compile space for usage in run-time stack and heap: execution 3.5 C rules: scope extends from declaration through end of block print statement variable 7 (in inner()) a: in main b: in middle 11 (in middle()) a: in main b: in middle 14 (in main()) a: in main b: in main C# rules: names must be declared before use, scope is throughout the block 7 a: in inner, but have compile-time error (use before initialization) b: in middle 11 a: in main b: in middle 14 a: in main b: in main 3.6 a. 9 4 2 3 b. main g: sl: null dl: null B a: 3 x: 1 sl: points to main's frame dl: points to main's frame R m: 1 (1) sl: points to B's frame dl: points to B's frame R m: 2 (2) sl: points to B's frame dl: points to R(1)'s frame R m: 3 (3) sl: points to B's frame dl: points to R(2)'s frame A n: 3 sl: points to B's frame dl: points to R(3)'s frame c. A follows its static link chain 2 steps (A -> B -> main, i.e., to main's frame), then go to offset to g (in main's frame). 3.7 a. Brad's code runs out of memory. Java has garbage collection, so Brad thinks that when he sets a new value to L (his code L = reverse (L)) the objects in the original L list will be collected by the garbage collector (because with the reassignment to L, nothing points to the first element of the list L (after Brad's while loop has completed. But there is no garbage collector in C, so both lists (valid and invalid) will occupy heap space. b. Brad's output is strangely corrupted. Aliasing problem! The library code for insert() and for reverse() both involve changing the next pointers of a node of L. 3.11 Z is real and declared in R A is real and is a parameter in R C is real and is a parameter in R X is real and declared in P 3.14 a. Static scope: 1 (in main), 1 (in main), 2 (in main), 2 (in main) b. dynamic scope: 1 (in main), 1 (in main), 2 (in second), 1 (in main)