<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 03.07.2019 08:58, Ondrej Pokorny
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:aeabaaad-dc9b-3ac8-e1e4-5f612a2e42d6@kluug.net">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>BTW I was always convinced that an explicit typecast switches
off range checking. And now I open the documentation <a
class="moz-txt-link-freetext"
href="https://www.freepascal.org/docs-html/prog/progsu65.html"
moz-do-not-send="true">https://www.freepascal.org/docs-html/prog/progsu65.html</a>
and I read this: (citation)<br>
<i>If, at run-time, an index or enumeration type is specified
that is out of the declared range of the compiler, then a
run-time error is generated, and the program exits with exit
code 201. This can happen when doing a typecast (implicit or
explicit) on an enumeration type or subrange type.</i></p>
</blockquote>
<p>More fun:</p>
<p><tt>program Project1;</tt><tt><br>
</tt><tt>{$R+}</tt><tt><br>
</tt><tt>type</tt><tt><br>
</tt><tt> TSubRange = 1..2;</tt><tt><br>
</tt><tt>var</tt><tt><br>
</tt><tt> S: TSubRange;</tt><tt><br>
</tt><tt>begin</tt><tt><br>
</tt><tt> S := Default(TSubRange);</tt><tt><br>
</tt><tt> Writeln(S);</tt><tt><br>
</tt><tt>end.</tt><br>
</p>
<p>compiles and runs just fine. Why?</p>
<p>This does not compile:</p>
<p>program Project1;<br>
{$R+}<br>
type<br>
TSubRange = 1..2;<br>
var<br>
S: TSubRange;<br>
begin<br>
S := 0;<br>
Writeln(S);<br>
end.<br>
<br>
</p>
<p>Ondrej<br>
</p>
</body>
</html>