[Oberon] Easter eggs in Oberon

August Karlstrom fusionfile at gmail.com
Mon Apr 13 15:16:19 CEST 2020


On 2020-04-12 13:00, Joerg wrote:
> There is no „byte multiplication“; 

The language report says that

"The operators +, −, *, and / apply to operands of numeric types. Both 
operands must be of the same type, which is also the type of the result."

If both operands have type BYTE then multiplication is BYTE 
multiplication as far as the language is concerned. It will probably be 
implemented using 32-bit or 64-bit multiplication but that's an 
implementation detail.

> the type BYTE modifies the assignment not the multiplication;
> After these statements
>      b := -2;

In the language report BYTE is defined as "the integers between 0 and 
255" and "The type BYTE is compatible with the type INTEGER, and 
vice-versa." This implies that INTEGER is compatible with BYTE *only* if 
the value is between 0 and 255. Therefor the above statement is invalid.

>      b := b * 256;

Here, b on the right hand side is interpreted as an INTEGER and the type 
of the product is INTEGER. The result is then interpreted as a BYTE and 
assigned to b. The statement above is well defined only when b = 0.

> b is 0 although the multiplication results in 65024. Can be verified by these statements >      b := -2;
>      i := b * 256;
When the result is undefined you can potentially get anything.


-- August


More information about the Oberon mailing list