[fpc-pascal] QWord/UInt64 and Range Check Errors

Inoussa OUEDRAOGO inoussa12 at gmail.com
Thu Jun 25 20:33:50 CEST 2009


2009/6/25 Jonas Maebe <jonas.maebe at elis.ugent.be>:
>
> On 25 Jun 2009, at 20:14, Inoussa OUEDRAOGO wrote:
>
>> 2009/6/25 Jonas Maebe <jonas.maebe at elis.ugent.be>:
>>>
>>> On 25 Jun 2009, at 19:58, Ruediger Hahn wrote:
>>>
>>>> I am just wondering if this is a bug: Can anyone tell me why I get a
>>>> "range check error while evaluating constants" with the following simple
>>>> program:
>>>>
>>>> <code>
>>>> program Project1;
>>>>
>>>> const
>>>> MyVar : UInt64 = $FFFFFFFFFFFFFFFF; // 4 x 2 Bytes or 4 Words
>>>>
>>>> begin
>>>> end.
>>>> </code>
>>>
>>> The reason is that $FFFFFFFFFFFFFFFF is parsed as an int64 by FPC. As a
>>> result it equals -1, and -1 is not a valid uint64 value.
>>
>> This warning is actually misleading
>
> Not warning would be misleading (and wrong).
>
>> as it makes one doubtfull about
>> the correctness of the program( In my case I debugged the program to
>> be sure that the "good" value was assigned).
>
> When it's changed, you will get the warning/error when assigning this value
> to an int64 and then those cases can be debugged.

and that seems more accurate to me

> to an int64 and then those cases can be debugged. It's the same when we
> changed from parsing $80000000-$FFFFFFFF as a longint to parsing it as a
> cardinal. Suddenly a whole bunch of code no longer worked correctly anymore
> then either, and we got a bunch of questions why code no longer compiled or
> produced warnings.

IMHO warnings/errors should be reported as one is actually in a "out
of range" case. But if some code depends on this ( such as a bit mask
) changing the behavior of the compiler can effectively be harmfull.
I think that should be up to the people (ab)using the parser this way
to correct their code by doing a explicit typecast.

-- 
Inoussa O.



More information about the fpc-pascal mailing list