[fpc-pascal]Cardinal Assignment

Jonas Maebe jonas at zeus.rug.ac.be
Sat Jun 22 20:24:08 CEST 2002


On Thu, 20 Jun 2002, Chuck welch wrote:

> With fpc 1.0.4 the following compiles ok on linux:
>
> var
>
>   card : cardinal;
>
> Begin
>   card := 3858954154;
> end.

The reason is that

a) the 1.0.x compiler handles all integer constants as longints internally
b) val() for longints was broken in 1.0.4, in that it accepted cardinal
values
c) range checking for cardinal-longint conversions was not implemented

> But under 1.0.6 I get a "Incompatible types: got "S80REAL" expected "ULONG"

Indeed, now the compiler detects that that is not a valid longint value,
so it parses it as a floating point number.

> Trying to do a card := Round() or Trunc results in a range check error.

That's because round() and trunc() also return longints in 1.0.4 I think
(and even if they didn't, this expression would be evaluated at compile
time, so the result would be stored internally again as a longint, giving
the same result).

> How can I assign a value this large to a cardinal?

I think the only way is to use hex notation and then adding an explicit
cardinal() typecast round the value.


Jonas





More information about the fpc-pascal mailing list