Sign in Join

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

Mailing lists / fpc-pascal / 2004-04

QWORD error ?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Unknown author

Hi All,

I'm sorry, but i'm having trouble using 64-bits QWORD arithmetic. This results i got with IDE 0.9.2 5.4.2004, compiler 1.9.3.

var L : Longint;
    qw : qword;
begin
  qw:=100;
  qw:=qw-1;                   { qw=99 O.K. }
  L:=1;
  qw:=qw-L;                   { qw=98 O.K. }
  L:=-1;
  qw:=qw+(-L);                { qw=99 O.K. }
(*
  qw:=qw-L;                   { run time error 201 }
  qw:=qw+L;                   { run time error 201 }
*)
  qw:=qw+int64(L);            { qw=98 O.K. }
  L:=1;
  qw:=qw+int64(-L);           { qw=4294697393 O.K. ? }
  qw:=qw+int64(-1);           { qw=4294697392 O.K. ? }
(*
  qw:=qw+(-1);                { range check error while evaluating constants
}
*)
end.

Could somebody help me what's wrong ?
Many thanks for your useful help.

Lubomir Cabla/CBL

Reply by email

Jonas Maebe
to Unknown author
Show quoted text 6 lines
L:=-1; qw:=qw+(-L); { qw=99 O.K. } (* qw:=qw-L; { run time error 201 } qw:=qw+L; { run time error 201 } *)

[snip]

Could somebody help me what's wrong ?

The problem is that the compiler has to convert both operands to the same type when you do an operation. When you are working with the largest supported unsigned type (qword currently), this means that both operands are first converted to qword. -1 is an invalid value for a qword, so you get a range check error.

That's also the reason why Turbo Pascal only supported longint, and not cardinal: it breaks range checking.

Jonas

Reply by email