[Oberon] Type compatibility rules for Pointers

Chris Burrows chris at cfbsoftware.com
Tue Jun 16 09:30:22 CEST 2020


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Tomas
> Kral
> Sent: Tuesday, 16 June 2020 4:38 PM
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] Type compatibility rules for Pointers
> 
> 
> I found this even more interesting..
> 
> MODULE Types; (*type compatibility*)
>   TYPE
>     P1 = POINTER TO R1;
>     P2 = POINTER TO R2;
> 
>     R1 = RECORD END;
>     R2 = RECORD (R1) END;
> 
>    PROCEDURE Test*;
>      VAR p1: P1; p2: P2;
>    BEGIN NEW(p1); NEW(p2);
> 
>      (*possible*)
>      IF p1 IS p2 THEN (*true*) END ;
>      p1 := p2;
> 
>      (*not possible*)
>      IF p2 IS p1 THEN (*true*) END ;
>      p2 := p1;
> 
>    END Test;
> END Types.Test
> 

If you do not understand why this is so, the most comprehensible explanation
of this behaviour, that I have found, is in: 

Section 5.2 Compatibility of a Base Type and Its Extension, in Hanspeter
Mössenböck's book: Object-Oriented Programming in Oberon-2.

http://ssw.jku.at/Research/Books/Oberon2.pdf

Regards,
Chris Burrows
CFB Software
https://www.astrobe.com/RISC5




More information about the Oberon mailing list