[Oberon] How to use SYSTEM.VAL safely?
jmaggio14 at gmail.com
Wed Mar 31 17:16:34 CEST 2021
I'm new to the world of RISC5 and Oberon
I'm curious about the dangers of using SYSTEM.VAL for casting or type
conversion. I need to do bitwise operations on Integers and was planning on
converting them to SETs using SYSTEM.VAL. However, this webpage
<https://en.wikibooks.org/wiki/Oberon/ETH_Oberon/faqlang#bitwise> warns me
to avoid using SYSTEM.VAL because it can break garbage collection, but I
wasn't able to find any of Wirth's own documentation about it. I'm assuming
that means that there is a potential for a memory leak if not used properly?
How can I make sure I'm using SYSTEM.VAL safely? Is the following example
PROCEDURE SetVal*(val : INTEGER);
> (* only values between 0 and 99 are valid*)
> VAR digit1, digit2 : SET;
> (* Convert the integer into 2 binary-coded decimal digits*)
> digit1 := SYSTEM.VAL(SET, val DIV 10);
> digit2 := SYSTEM.VAL(SET, val MOD 10);
> digit1 := LSL(digit1, 4);
> SYSTEM.PUT(SEVENSEGADR, digit1 + digit2);
> END SetVal;
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Oberon