[Oberon] Compiler behaviour for a32 := a8

Chris Burrows chris at cfbsoftware.com
Tue Feb 2 01:55:30 CET 2021


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> August Karlstrom
> Sent: Tuesday, 2 February 2021 7:47 AM
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] Compiler behaviour for a32 := a8
> 
> On 2021-02-01 14:39, Hans Klaver wrote:
> > Chris wrote:
> >
> >> The key point is that Item 2 in the earlier definition has been
> >> removed and the rule "The type of the expression must be the same
> as
> >> that of the designator" now applies to array assignments. Hence
> a32
> >> := a8 is no longer allowed.
> >
> > Contrary to the latter rule that you cite a variable of one
> character
> > array type now can be assigned to a variable of quite another
> > character array type (provided the two array types have the same
> > length). This is a breach in the type checking that amazes me.
> 
> As mentioned before in this mailing list, I asked Niklaus Wirth in
> 2017 if structural equivalence of arrays and procedures is to be seen
> as a language extension and he answered:
> 
> "Yes, I consider this type compatibility as an addition to the
> language definition. I think it makes sense, and it is easy to
> implement. Please look at the source of the compiler under Project
> Oberon."
> 
> What I don't understand is why it hasn't been added to the language
> report if he thinks it both makes sense and is easy to implement.
> 

Note that when the language was updated he did add:

4. An open array may be assigned to an array of equal base type

Which should allow you now to write:

   TYPE
     Ident = ARRAY 32 OF CHAR;
   VAR
     a8:  ARRAY 8 OF CHAR;
     a32: ARRAY 32 OF CHAR;
     id1, id2: Ident;

 PROCEDURE Assign(VAR dst: Ident; src: ARRAY OF CHAR);
 BEGIN
   dst := src
 END Assign;
 ...
 ...
 Assign(id1, a8);
 Assign(id2, a32);

Which is not too laborious as an alternative to 

   id1 := a8;

and also allows the equivalent of:

   id2 := a32;

You can expect a runtime error if src is larger than dst.

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






More information about the Oberon mailing list