HP Pascal/iX Programmer's Guide (31502-90023)

6- 6
new(v,a,f); {illegal -- with variant a, variant f is impossible}
END.
Example 4
This program is semantically equivalent to the program in the immediately
preceding example (Example 3), and the declaration order of the tag
fields is the same.
PROGRAM prog;
TYPE
arectype = RECORD
i : integer;
CASE t2 : (c,d) OF
c : (j : integer);
d : (k : real);
END;
brectype = RECORD
CASE t3 : (e,f) OF
e : (l : real);
f : (m : char);
END;
r = RECORD
f1 : integer;
CASE t1 : (a,b) OF
a : (arec : arectype);
b : (brec : brectype);
END;
rptr = ^r;
VAR
v : rptr;
BEGIN
new(v);
new(v,a);
new(v,a,c);
new(v,a,d);
new(v,,d); {illegal -- must specify a}
new(v,d); {illegal -- must specify a}
new(v,b);
new(v,b,e);
new(v,e,b); {illegal -- tags are not in order of declaration}
new(v,b,f);
new(v,a,f); {illegal -- with variant a, variant f is impossible}
END.
You do not have to specify tag fields. If you omit them,
new
allocates
enough space for the largest possible variant, wherever there are
variants. This allocation is the default allocation for variables of the
particular record type.
If you use tags to specify smaller variants,
new
allocates less than the
default allocation to the new variable. The advantage to using tags is
that you save space. The disadvantage is that the new variable cannot
appear in an assignment statement, or as an actual parameter.
(Assignment statements and formal parameters use the default allocation.)
It is legal for the fields of the new variable to appear as actual
parameters, and to be used in a field by field assignment.
Example 5
PROGRAM prog;
TYPE
rec = RECORD
CASE t : (a,b) OF
a : (a1,a2 : integer);
b : (b1,b2,b3,b4,b5,b6 : integer);
END;