HP Pascal/iX Reference Manual (31502-90022)

9- 2
new
Usage
new(
p
)
new(
p, t1,...,tn
)
Parameters
p
Any pointer variable.
t
A case constant value representing tag values for the pointer
variable
p
.
Description
The procedure new(
p
) allocates storage for a dynamic variable on the heap
and assigns its identifying value to the pointer variable
p
.
If the dynamic variable is a record with variants, then the tag may be
used to specify a case constant. This constant determines the amount of
storage allocated. For nested variants, the values must be listed
contiguously and in order of their declaration. The procedure call does
not assign the specified tag values to the tag fields of the dynamic
variable.
If new is called for a record with variants and no case constants are
specified, the compiler determines storage by the size of the fixed part
plus the size of the largest variant.
NOTE You cannot use an entire dynamic record variable allocated with one
or more case constants as an actual parameter, or in an assignment
statement.
Note that the pointer variable may be a component of a packed structure.
Pointer dereferencing accesses the actual values stored in a dynamic
variable on the heap.
Example
PROGRAM show_new (output);
TYPE
marital_status = (single, engaged, married, widowed, divorced);
year = 1900..2100;
ptr = ^person_info;
person_info = RECORD
name: string[25];
birdate: year;
next_person: ptr;
CASE status: marital_status OF
married..divorced: (when: year;
CASE has_kids: Boolean OF
true: (how_many: 1..50);
false: ();
);
engaged: (date: year);
single : ();
END;
VAR
p : ptr;
BEGIN { Various legal calls of new. }
.
.
new(p); { Allocates record of the largest size. }