[fpc-pascal] Convert to int64 note

Michael Van Canneyt michael at freepascal.org
Fri Jul 14 14:13:35 CEST 2017



On Fri, 14 Jul 2017, james at productionautomation.net wrote:

>> What's the type of each variable?
>
> Last_GS,G_End : longint;
> Max_Program_to_Display : Word;
>
> -----Original Message-----
> From: fpc-pascal [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Santiago A.
> Sent: Friday, July 14, 2017 7:00 AM
> To: fpc-pascal at lists.freepascal.org
> Subject: Re: [fpc-pascal] Convert to int64 note
>
> El 14/07/2017 a las 1:13, james at productionautomation.net escribió:
>> I've been trying to get my programs to compile without any warnings or notes, but I keep getting this one:
>>
>> promill.pas(2137,42) Hint: Converting the operands to "Int64" before doing the subtract could prevent overflow errors.
>>
>> I get it a lot, but this is the line the above example is from:
>>
>> Last_GS:=G_End-(Max_Program_To_Display-1);
>>
>> Can someone please explain that this hint means and how I would convert the operands to "Int64" as recommended?

It means that if for example
   G_End = -Maxint
then Last_GS can get a value that falls outside the valid integer range.

If you declare Last_GS as int64, you should not get the warning.

Michael.


More information about the fpc-pascal mailing list