josef@ugun21.UUCP (01/26/89)
fransvo@htsa.UUCP (Frans van Otten) writes
>"What is the use of tag fields and case labels"
Well, in Your example, they are of no other use than to identify
the different variants of this record.
But one could add an identifier to the CASE, e.g.
TYPE Example = RECORD
CASE tag : CARDINAL
OF
1 .. 10 : a : INTEGER;
b : BOOLEAN |
11 .. 15 : u : CHAR;
v : ARRAY[1 .. 10] OF CHAR
ELSE z : CHAR
END
END;
Then You use "tag" as a field of the record AND a selector for the variants.
A "useful" example is:
TYPE CoordType = (cartesian, cylinder, polar);
TYPE Point = RECORD
CASE CoordSystem: CoordType OF
cartesian: x, y: INTEGER |
cylinder: elevation INTEGER;
radius: CARDINAL;
angle: REAL |
polar: radius: CARDINAL;
azimuth, elevation: REAL
END
END;
Now You can store information about the kind of coordinate system You are
using as well as the coordinates applicable.
IMHO The usage of the "variant record" (as it is called in PASCAL)
WITHOUT the named tag field is more or less a mis-use.
How will You ever find out which variant to use when You haven't
stored any hints (If You have stored any, You can use them as tag fields!)
Josef Moellers
paper mail: e-mail:
c/o Nixdorf Computer AG USA: uunet!linus!nixbur!mollers.pad
Abt. EG-3 !USA: mcvax!unido!nixpbe!mollers.pad
Unterer Frankfurter Weg
D-4790 Paderborn
tel.: (+49) 5251 104691
Standard disclaimer: Blablabla opinion blablabla employer blablabla!