Contents | Prev | Next | Index
Variables of a pointer type P assume as values pointers to variables of another type T. T is called the pointer base type of P and must be a record or array type.
pointer_type ::= POINTER TO type ::= POINTER TO open_array type open_array ::= open_array ARRAY OF ::= ARRAY OF |
Pointer types adopt the extension relation of their pointer base types: if a type T1 is an extension of T, and P1 is of type POINTER TO T1, then P1 is also an extension of P.
If p is a variable of type P = POINTER TO T, a call of the standard procedure NEW allocates memory from a heap and assigns the pointer variable to its address. The allocated memory is a new instance of type T. Standard procedure NEW is called as:
NEW( p )
This Oberon-2 compiler also allows the following extended call of NEW:
NEW( p, x0, x1, ... )
The additional parameters are used in constructor call for Java. In Oberon-2, constructors can be declared like regular type-bound procedures except that they are to be preceded by the comment embedded directive (*$JAVA CONSTRUCTOR*).
If the pointer base type is an n-dimensional open array, the allocation has to be done as follows:
NEW( p, e0, e1, ... )
where the additional actual parameters are integers specifiying the array lengths for each dimension.
An operand p designates a variable of its pointer type, whereas an operand p^ designates a variable of pointer base type T whose instance was allocated from the heap.
Any pointer variable may assume the value NIL, which points to no variable at all.
There is no need for explicitly deallocating memory blocks because this is automatically done by Java's garbage collection of the heap.
Contents | Prev | Next | Index
Canterbury Oberon-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com