Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2001-06

bugs on 64-bits integers?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Wirawan Purwanto

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;
begin
  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);
end.

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.

Thanks,
Wirawan

Reply by email

Jonas Maebe
to Wirawan Purwanto
Wirawan Purwanto wrote 5 lines
x min = 0 x max = 0 See that the maximum and minimum values of the 64-bit integers are off. Do you know why?

Yes, it was a bug in 1.0.4. It's already fixed in the mean time (you can always download a 1.0.5 snaphot from
<ftp://fpt.freepascal.org/pub/fpc/snapshot/v10> to verify this if you want).

Jonas

Reply by email