[fpc-pascal] QWord/UInt64 and Range Check Errors
Ruediger Hahn
ruediger.hahn at itservices-hahn.de
Thu Jun 25 20:52:57 CEST 2009
Jonas Maebe wrote:
>
> 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.
Ah yes, now I see. In Delphi it is quite the opposite: There I get a
warning when I try to assign this value to an Int64: "Constant
expression violates subrange bounds". Unfortunately it took me some
hours to solve this problem because Lazarus by default has range
checking enabled (-Cr), so I got an error instead of a warning.
Furthermore IMHO hex values _by_ _default_ should be interpreted as
positive values. But that might be a matter of taste.
So what do I have to do then? It seems that a cast is the best solution:
<code>
MyConst : UInt64 = UInt64($FFFFFFFFFFFFFFFF);
</code>
Am I right?
Ruediger
More information about the fpc-pascal
mailing list