<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Jeff<div><br></div><div>For bitwise operations SYSTEM.VAL is safe.<div>The hint to the garbage collection is rather meant in case you manipulate POINTERs by doing calculations on them using INTEGERs.</div><div>Common low-level programming practice</div><div><br></div><div>BTW: If I understand correctly what you want to do with SetVal is, interprete the decimal input value as hex nbr.</div><div><div><br></div><div>SetVal(73) will store value 115 at address SEVENSEGADR.</div></div><div><br></div><div>If so, I would code it as follows:</div><div>SYSTEM.PUT(SEVENSEGADR,</div><div> val DIV 10*16 + val MOD 10);</div><div><br></div><div>Perhaps an other method would be to call SetVal with the hex value in the first place:</div><div>SetValue(73H);</div><div>and SerVal just does</div><div> SYSTEM.PUT(SEVENSEGADR, val)</div><div><br><div dir="ltr">br<br><div>Jörg</div></div><div dir="ltr"><br><blockquote type="cite">Am 31.03.2021 um 17:17 schrieb Jeff Maggio <jmaggio14@gmail.com>:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">Hi All!<div><br></div><div>I'm new to the world of RISC5 and Oberon</div><div><br></div><div>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, <a href="https://en.wikibooks.org/wiki/Oberon/ETH_Oberon/faqlang#bitwise">this webpage</a> 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?</div><div><br></div><div>How can I make sure I'm using SYSTEM.VAL safely? Is the following example "safe"?</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> PROCEDURE SetVal*(val : INTEGER);<br> (* only values between 0 and 99 are valid*)<br> VAR digit1, digit2 : SET;<br> BEGIN<br> (* Convert the integer into 2 binary-coded decimal digits*)<br> digit1 := SYSTEM.VAL(SET, val DIV 10);<br> digit2 := SYSTEM.VAL(SET, val MOD 10);<br> digit1 := LSL(digit1, 4);<br> SYSTEM.PUT(SEVENSEGADR, digit1 + digit2);<br> END SetVal;</blockquote><div><br></div><div><br></div></div>
<span>--</span><br><span>Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems</span><br><span>https://lists.inf.ethz.ch/mailman/listinfo/oberon</span><br></div></blockquote></div></div></body></html>