Hello,

I don't want to start a big discuss on the subject (it would
presumably lead nowhere) but I would like to answer to both J.M. and
P.V. who added notes to the report.


To J.M.
-------
You said "To be compatible with Delphi". With its current behaviour,
FPC 2.1.4 is not compatible with Delphi (and no more with FPC 2.0.4).

You quoted the bug #8321. There, I see two problems but none concerns
the subtraction of unsigned integers.

1) The problem in the bug report.
   "Edit1.text:=(intToStr(a + b - 256));".
   Calling an overloaded function with a value whose type is not
   clearly defined (a and b are bytes but 256 is not) is, at least,
   dangerous programming.

2) The problem in FPC.
   For some reasons, FPC decided to call IntToStr(Int64) (here, Delphi
   called IntToStr(Longint)). But, instead of extending the parameter as
   a signed number, it extended it as an unsigned one. This is not
   coherent. Since FPC selected a signed parameter overload, it should
   have extended the parameter with

     mov  eax, param
     cdq

   not with, as it did,

     mov  eax, param
     mov  edx, 0


To P.V.
-------
Compelling FPC 2.1.4 to behave like FPC 2.0.4 is not very difficult.
In a program where you have "A := B - C;" (A,B,C being Longwords), it
is sufficient to write "A := Longword(Longint(B) - Longint(C));" and all
is right. The most difficult is to find which lines of code has to be
modified. FPC signals most of them ("Possible loss of data ...") but not
all. For instance, "if (A and (A-1)) = ..." is silently converted as a
64-bit operation.

But the problem is not just an efficiency problem, it is also a 'result'
problem. For instance, try this with both FPC 2.0.4 and 2.1.4 :

  B := 1111;
  C := 1112;
  D := 311;
  A := (B - C) div D;

You will get two different values for A.
With 2.0.4, you compute ((B - C) mod 2^32) div D; with 2.1.4, you
compute (B - C) div D where (B - C) is a 64-bit signed parameter. These
are two different operations.

mm
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to