[fpc-pascal] Why does not assignment from int64 to integer trigger warning?

Jichao Yang jcyangzh at gmail.com
Thu Jan 14 20:12:15 CET 2010


@Jonas, Thanks,it works well.

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:

byteVal := 256;

It will produce 'Error: range check error while evaluating constants';

In conclusion,free pascal do provide mechanism to detect
type-catagory-inside check,even thought IMHO,it's not perfect.

jcyang.

On Fri, Jan 15, 2010 at 1:02 AM, Jonas Maebe <jonas.maebe at elis.ugent.be>wrote:

>
> On 14 Jan 2010, at 16:30, Jichao Yang <jcyangzh at gmail.com> wrote:
>
> int64Val := 2147483648; { 2^32 }
>> intVal := int64Val; { does not trigger any warnings }
>>
>
> 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.
>
>
> Now the intVal should be 0 which is not what I wanted
>>
>
> Enable range checking, and you will get a run time error.
>
>
> Jonas
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100115/5549a463/attachment.html>


More information about the fpc-pascal mailing list