<div>Hi!</div><div><br /></div><div><br /></div><div> As I remember, Oberon compiler Ofront+ contain safe implementation FOR cycle.</div><div><br /></div><div><br /></div><div>Best regards, Victor Miasnikov </div><div><br /></div><div>24.05.2022, 19:30, "Rodney Bates" <rodney.bates@gmx.com>:</div><blockquote>
<br />
<div class="15884596b1d713f0af90ca72e2c3c37moz-forward-container"><br />
<br />
-------- Forwarded Message --------
<table class="956b4ff9e4f5235b15f7681490de2546moz-email-headers-table" border="0" cellpadding="0" cellspacing="0"><tbody><tr><th>Subject:
</th><td>Re: [modula3/cm3] The definition of the FOR loop is
prone to integer overflow (Issue #1027)</td></tr><tr><th>Date: </th><td>Mon, 23 May 2022 12:47:20 -0500</td></tr><tr><th>From: </th><td>Rodney Bates <a class="1f85fe41a9161661477b40489dd2f552moz-txt-link-rfc2396E" href="mailto:rodney.bates@gmx.com" target="_blank"><rodney.bates@gmx.com></a></td></tr><tr><th>Reply-To:
</th><td><a class="324de92b3f6b2f5e993df2fdf11fa1c7moz-txt-link-abbreviated" href="mailto:rbates@acm.org" target="_blank">rbates@acm.org</a></td></tr><tr><th>To: </th><td>modula3/cm3
<a class="1f85fe41a9161661477b40489dd2f552moz-txt-link-rfc2396E" href="mailto:reply+ABSVZNBJBSNDOC4KAPQ3PFWATCZIVEVBNHHEUKY5UY@reply.github.com" target="_blank"><reply+ABSVZNBJBSNDOC4KAPQ3PFWATCZIVEVBNHHEUKY5UY@reply.github.com></a>,
Norayr Chilingarian <a class="1f85fe41a9161661477b40489dd2f552moz-txt-link-rfc2396E" href="mailto:notifications@github.com" target="_blank"><notifications@github.com></a>,
modula3/cm3 <a class="1f85fe41a9161661477b40489dd2f552moz-txt-link-rfc2396E" href="mailto:cm3@noreply.github.com" target="_blank"><cm3@noreply.github.com></a></td></tr><tr><th>CC: </th><td>Subscribed <a class="1f85fe41a9161661477b40489dd2f552moz-txt-link-rfc2396E" href="mailto:subscribed@noreply.github.com" target="_blank"><subscribed@noreply.github.com></a></td></tr></tbody></table>
<br />
<br />
<br />
<br />
<div class="5b9634d4c5f0a371e6378bc999480cfemoz-cite-prefix">On 5/23/22 07:37, Norayr Chilingarian
wrote:<br />
</div>
<blockquote>
<p dir="auto">i am sorry that i ask without knowing, but does
the compiler check (at compile time of course) if the variable
used for the looping potentially can overflow?</p>
<p dir="auto">let's say we have i: INTEGER; l: LONGINT;<br />
</p>
</blockquote>
This ..............^ declaration of i is irrelevant, because<br />
the FOR loop is an inner scope and declares its own meaning<br />
of i.<br />
<blockquote>
<p dir="auto"> would this generate a compile time error?</p>
<pre class="d9e87658e009a29671d33b50f72d3a60notranslate"><code class="d9e87658e009a29671d33b50f72d3a60notranslate">FOR i := 0 to l DO</code></pre>
</blockquote>
<code>Yes, but for a reason possibly different from what you may
mean. <br />
<br />
This is statically illegal because first and last must have the<br />
same base type (which is the type this inner i will be given.)<br />
INTEGER and LONGINT are distinct base types and are not mutually<br />
assignable, to prevent a cascade of questions about the sizes of
<br />
intermediate arithmetic and results in expressions. <br />
<br />
There are no implicit type conversions in Modula-3, although<br />
assignability provides something roughly equivalent in specific<br />
cases. <br />
<br />
This is unlike CHAR and WIDECHAR, which, though different base
types,<br />
are mutually assignable without trouble, because there are no<br />
arithmetic operations producing results of either type.<br />
<br />
But you could write FOR i := 0L TO l DO ...<br />
<br />
and the only overflow questions would be when Last is at one of<br />
the very ends of LONGINT, as discussed in Roland Illig's article<br />
referenced in his recent post. <br />
<br />
See 2.3.16, 2nd paragraph, not counting the line of sample code.<br />
<br />
<br />
</code>
<blockquote>
<pre class="d9e87658e009a29671d33b50f72d3a60notranslate"><code class="d9e87658e009a29671d33b50f72d3a60notranslate">
...
END
</code></pre>
<p style="color:#666;font-size:small">—<br />
Reply to this email directly, <a href="https://github.com/modula3/cm3/issues/1027#issuecomment-1134622763" target="_blank">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABSVZNBALWPAWALZMDI3DETVLN3YVANCNFSM5WTZAWUA" target="_blank">unsubscribe</a>.<br />
You are receiving this because you are subscribed to this
thread.<img height="1" src="https://github.com/notifications/beacon/ABSVZNGLBMJN4VO3ASSQ24TVLN3YVA5CNFSM5WTZAWUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIOQPQKY.gif" width="1" /><span style="display:none;font-size:0;height:0;max-height:0;max-width:0;overflow:hidden;visibility:hidden;width:0">Message
ID: <modula3/cm3/issues/1027/<a href="mailto:1134622763@github.com" target="_blank">1134622763@github.com</a>></span></p>
</blockquote>
<br />
</div>
,<p>_______________________________________________<br />M3devel mailing list<br /><a href="mailto:M3devel@elegosoft.com" target="_blank">M3devel@elegosoft.com</a><br /><a href="https://m3lists.elegosoft.com/mailman/listinfo/m3devel" target="_blank">https://m3lists.elegosoft.com/mailman/listinfo/m3devel</a><br /></p></blockquote>