Assignment 5, Record, union, and pointer types
Due 10/07/03 12 noon
(To be done with your group)

  1. If a language wants to support garbage collection, the language must be designed appropriately.  In other words, one cannot design a language while being oblivious to garbage collection and hope that it will "just work" with garbage collection.  The language must be designed such that the garbage collector is able to: (a) find all the pointers in memory; and (b) identify which object each pointer points to.
    1. Explain the need for the two requirements given above
    2. Does C++ support these two requirements?  Support your answer either with quotes from the C++ language definition (available in the "interesting links" section of the class web page) or with examples and their output (much like how you use the PL Detective) from a C++ compiler/run-time system
  2. Languages differ greatly in how they handle arrays.  In this question we will focus on one issue with arrays: what happens when one array is assigned to another (assuming the two arrays are of compatible types).  Consider, for example, two variables declared as follows in MYSTERY syntax:

    VAR a: ARRAY[1 TO 5] OF INTEGER;
    VAR b: ARRAY[1 TO 5] OF INTEGER;
    BEGIN ... END;

    What happens when we have an assignment a := b?   If the assignment is "by reference" (which is how Java works), variables of array type are represented as pointers and the outcome of the assignment is that a ends up pointing to the same array that b points to (i.e., alias).  If the assignment is "by value" (which is how Modula-3 works), then the assignment copies the contents of array b to array a

    1. Use this link to figure out if MYSTERY uses array assignment by reference or by value.  Your answer to this question should describe which one MYSTERY uses and also provide the evidence that enabled you to come to your conclusion.  You submissions may execute up to a total of 6 PRINT statements.  Additional attempts will be charged at 5% of this question's points per executed PRINT.
    2. Discuss the relative advantages and disadvantages of array assignment by value and array assignment by reference.  Refer to the "Characteristics" (i.e., first column) in Table 1.1 of Sebesta in your arguments.
  3. The first paragraph of 6.8.3 while talking about constrained variant variables says: "In this way the user can tell the system when the type checking can be static"
    1. Describe in your own words what a "constrained  variant variable" is.
    2. Explain why type checking for a constrained variant variable can be static.