[Oberon] Type compatibility rules for Pointers

chris chris at gcjd.org
Mon Jun 15 21:09:40 CEST 2020


Hello,

please look at the following example:

TYPE
	R = RECORD i : INTEGER END;
	P1 = POINTER TO R;
	P2 = POINTER TO R;

PROCEDURE Test();
VAR
	p1 : P1; p2 : P2;
BEGIN
	NEW(p1); NEW(p2);
	IF p1 IS P2 THEN (* true *) END;
	p1 := p2;
END Test;

The dynamic type test is not a surprise as the type tag refers to the 
same record descriptor although I think it's a bit counter intuitive.

I am a bit confused that p1 := p2 compiles without errors. The 
Oberon-07 report says:
"The type of the expression must be the same as that of the designator"
and gives a list of 4 exceptions. Here only number 3 is of interest:

"3. In the case of records, the type of the source must be an extension 
of the type of the destination."

But in my understanding pointers are not records and P1 and P2 are 
different types.

Any comments?

Greeting, chris



More information about the Oberon mailing list