[Oberon] Easter eggs in Oberon
skulski at pas.rochester.edu
Mon Apr 13 23:35:31 CEST 2020
>you could apply this to BYTE: if the result is not in the range 0..255 it just wraps around or overflows or underflows, but is not undefined.
Perhaps the term should not be "undefined", but rather "unspecified".
I would ask, why do we need BYTE as an integer subtype (or integer subrange)? Why do we need math on BYTE values? BYTE math is implemented with 32-bit integer math. So why not use the full INTEGER for calculations? If you need to sub-range an integer to (0..255), use MOD.
VAR b: BYTE;
b := 255; b := b+1; (* now b = 0; what we "somehow know" even though unspecified *)
The same can be achieved with MOD and then the result is both known and specified.
Maybe a better idea would be to allow BYTE as a package of 8 bits, but disallow any math whatsoever. All such math would be performed with INTEGER. If you need to wrap around, use MOD.
More information about the Oberon