[fpc-devel]bugs on 64-bits integers?

Wirawan Purwanto wirawan at camelot.physics.wm.edu
Sat Jun 2 03:52:08 CEST 2001

I've just started using FPC 1.0.4 for win32 and DOS right now. But I found a
nasty bug in the compiler. Could you spot it? Here is the sample code I used
(compile under Win32 or DOS/GO32V2):

program FPCtst;
//{$mode objfpc}
{$apptype console}

var x: qword;
    y: int64;
    L: longint;

  Writeln('Testing ', qword(maxlongint)*2);
  x := 1;
  writeln('max x = ', low(x), '...', high(x));
  writeln('max y = ', low(y), '...', high(y));
  L := low(l);
  writeln('l min = ', l);
  l := high(l);
  writeln('l max = ', l);

  x := high(qword);
  writeln('x min = ', x);
  x := high(x);
  writeln('x max = ', x);

The output is as follows:

Testing 4294967294
max x = 17179869184...17179869184
max y = 17179869184...17179869184
l min = -2147483648
l max = 2147483647
x min = 0
x max = 0

See that the maximum and minimum values of the 64-bit integers are off. Do
you know why? And the low and high function returns differently if it is
inside a Writeln statement or outside it.

I have double-checked these funny effects using my own
integer-to-hexadecimal-string function (I can send it to you if you want
it), and verified that they are all *correctly* wrong. And when I examine
the assembler outputs, the error is also there in the assembler. Hence it
must have been the compiler's error.

When replying, please include my address, since I am not currently
subscribed to FPC developer mailing list.


More information about the fpc-devel mailing list