Question 2 Whether two types are structurally equivalent is ultimately a matter of inter- pretation: the language designer decides which differences between two types are significant andwhich ones are not. On page 304 of the textbook, the following algorithm for determining structuralequivalence of two types A and B is given:1 Every type T can be represented as a string sT definedinductively:
If T is a built-in type, sT is its name.
If T is a composite of a sequence of subtypes T1, ..., Tk, then sT consists of the type constructor
used to construct T followed by the strings sT1 , . . .
, sTk .
For example, the string sT for the following type T is
“struct char pointer int”:
struct T { char x; int *y;
};
Two types A and B are structurally equivalent if and only if sA = sB.
(a) Argue why you cannot use this definition of type equivalence to decide whether the following
two types A and B are equivalent:
struct A { char x;
struct B *y; };
struct B { char x;
struct A *y; };
Get Answers For Free
Most questions answered within 1 hours.