Download Language Reference Manual

Transcript
The parameters d1,...,dn are compile-time or run-time ordinal values that must
be the same type as the formal discriminants of the object.
If the object of the pointer is of an undiscriminated schema type, you must
specify a d parameter for each of the formal discriminants of the schema type.
The d parameters discriminate the schema type in much the same way as
actual discriminants in a discriminated schema. The size of the allocation is
based on the value of the d parameters.
If the object is a schema record type, then you must use d parameters; you
cannot use t parameters or a combination of the syntaxes. If the schema record
type contains a variant (which depends on one of the formal discriminants)
then the d parameter discriminates the schema, determines the variant, and
allows Compaq Pascal to compute the necessary size of the allocation.
Note
If you specify t parameters to the NEW procedure, you must specify the
same t parameters to the DISPOSE procedure that deallocates memory
for the corresponding variable.
Consider the following examples:
TYPE
Meat_Type = ( Fish, Fowl, Beef );
Beef_Portion = ( Oz_10, Oz_16, Oz_32 );
Var_Record = RECORD
CASE Entree : Meat_Type OF
Fish : ( Fish_Type : ( Salmon, Cod, Perch, Trout );
Lemon : BOOLEAN );
Fowl : ( Fowl_Type : ( Chicken, Duck, Goose );
Sauce : ( Orange, Cherry, Raisin ));
Beef : ( Beef_Type : ( Steak, Roast, Prime_Rib );
CASE size : Beef_Portion OF
Oz_10, Oz_16 : ( Beef_Veg : ( Pea, Mixed ));
Oz_32
: ( Stomach_Cure :
( Bicarb, Antacid, None )));
END;
The_Schema( Upper_Bound : INTEGER )
= ARRAY [1..Upper_Bound] OF INTEGER;
VAR
To_Int
: ^INTEGER;
To_Var_Record : ^Var_Record;
To_Schema
: ^The_Schema;
Bound
: INTEGER VALUE 32;
{In the executable section:}
NEW( To_Int ); {Memory for To_Int^ allocated but not initialized}
8–32 Predeclared Functions and Procedures