Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-01

Why does not assignment from int64 to integer trigger warning?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jichao Yang
int64Val := 2147483648; { 2^32 }
intVal := int64Val; { does not trigger any warnings }

Now the intVal should be 0 which is not what I wanted.

my platform: v2.4.0[2009/12/18] for i386 under windows.

regards.
jcyang.

Jonas Maebe
to Jichao Yang
Jichao Yang 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

Jichao Yang
to Jonas Maebe

@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.

Jonas Maebe wrote 23 lines
On 14 Jan 2010, at 16:30, Jichao Yang 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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal