Addr a 1 1 2 addr a 1 10 11 1 5 10 2 1 10 6 10 1 10

Info icon This preview shows pages 2–4. Sign up to view the full content.

View Full Document Right Arrow Icon
addr (A [1, 1, 2]) = addr (A) + (((1 - (-10)) * 11) + (1 - (-5))) * 10 + 2 - 1) * 10 = 100 + ((11 * 11 + 6) * 10 + 1) * 10 = 12,810 7. Define the terms dangling reference , garbage , and memory leakage . Describe how each is created in a program and a possible solution to each. See textbook.
Image of page 2

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

View Full Document Right Arrow Icon
8. Consider the following Pascal program: program MAIN; var U, V : INTEGER; procedure A; var Y : INTEGER; ... (* point 4 *) end; procedure B; var U, V, Y : INTEGER; procedure C; ... begin ... (* point 3 *) A; ... end; begin (* B *) ... (* point 2 *) C; ... end; begin (* MAIN *) ... (* point 1 *) B; ... end. Indicate which activation records are stacked at each of points 1, 2, 3 and 4 in the program as well as the exact contents of those activation records. Assuming static scoping, show the contents of the display at each of these points. Assuming dynamic scoping, what is the scope of V at point 4? Static scoping 1) ARS = MAIN; DS = MAIN 2) ARS = MAIN, B; DS = MAIN, B 3) ARS = MAIN, B, C; DS = MAIN, B, C 4) ARS = MAIN, B, C, A; DS = MAIN, A Note: ARS is the activation record stack, DS is the display stack. With dynamic scoping, V belongs to B at point 4.
Image of page 3
9. Consider the functions below in C++-like pseudocode. int I; int F (int X, int Y) { I = 2; Y = 1; return X + Y; } void main (void) { int A [3]; A [0] = 7; A [1] = 11; A [2] = 13; I = 0; cout << F (A [I], I); } Show the values stored in the locations named A [0] , A [1] , A [2] , I , X and Y at the entry and exit points of function F assuming (a) call by value, (b) call by reference, (c) call by value-result, and (d) call by name? Also, show the result which gets printed in each case. The following table shows the results for each calling method. Call by A[0] i A[0] o A[1] i A[1] o A[2] i A[2] o I i I o X i X o Y i Y o Res value 7 7 11 11 13 13 0 2 7 7 0 1 8 reference 7 7 11 11 13 13 0 1 a1 a1 a2 a2 8 value-result 7 7 11 11 13 13 0 1 7 7 0 1 8 name 7 7 11 11 13 13 0 1 t1 t1 t2 t2 12 a1 - addr ( A [0] ) a2 - addr ( I ) t1 - thunk ( A [I] ) t2 - thunk ( I ) Assuming all parameters are passed by reference, does aliasing occur in this program? If so, where? Aliasing does occur in F as I may be referred to by its own name or by formal parameter Y.
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern