<div>@Jonas, Thanks,it works well.</div>
<div> </div>
<div>Turn on the range checking switch {$R+},the free pascal compiler would also seek for compile-time range error.For example,the follow line will not compile through:</div>
<blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
<div>byteVal := 256; </div></blockquote>
<div>It will produce 'Error: range check error while evaluating constants';</div>
<div> </div>
<div>In conclusion,free pascal do provide mechanism to detect type-catagory-inside check,even thought IMHO,it's not perfect.</div>
<div> </div>
<div>jcyang.</div>
<div> </div>
<div class="gmail_quote">On Fri, Jan 15, 2010 at 1:02 AM, Jonas Maebe <span dir="ltr"><<a href="mailto:jonas.maebe@elis.ugent.be">jonas.maebe@elis.ugent.be</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="im"><br>On 14 Jan 2010, at 16:30, Jichao Yang <<a href="mailto:jcyangzh@gmail.com" target="_blank">jcyangzh@gmail.com</a>> wrote:<br><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">int64Val := 2147483648; { 2^32 }<br>intVal := int64Val; { does not trigger any warnings }<br></blockquote>
<br></div>Assigning a longint to a byte does not generate a warning either. This is simply how Pascal works. If you want compile-time checks for such operations, use a language such as Ada instead.
<div class="im"><br><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Now the intVal should be 0 which is not what I wanted<br></blockquote><br></div>Enable range checking, and you will get a run time error.<br>
<br><br>Jonas<br>_______________________________________________<br>fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br><a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div><br>