[fpc-pascal] Currency constant wrongly stored in generated EXE?

LacaK lacak at zoznam.sk
Mon May 12 12:30:26 CEST 2014


> You have troubled me seriously, so I have dug in the compiler source.
>

:-)

>
>
> It appears that when parsing the source, Currency constants are cast 
> to type BestReal (EXTENDED on I386) before being converted to the 8 
> byte currency written to the PPU or EXE or whatever is done. 

it was my expectation also

> The combination of these steps DO USE FPU instructions on the I386, 
> the compiler does not use SysUtils.StrToCurr to create the 8 bytes 
> currency.
>
>
>
> As a bean counter, the point that was really scaring me was whether 
> additions and subtractions of Currency's with Currency's would use the 
> FPU. It appears that the generated (ASM) code actually uses Int64 
> arithmetic's for these 2 operations. Ouf...
>
>
>
> I run FPC 2.6.4 on WinXP machine with an Intel Core 2 CPU 6400 @2.13 
> GHz s
>
>
>
> Here after a program that should test if the compiler is run on a 
> problematic CPU
>
>
>
> ==============================================
>
> program test_Currency_loop;
> var
>  c:currency;
>  cAsInt:Int64;
>  // cAsInt64:Int64 absolute c;
>  ix:integer;
> begin
>  c:=92233720368547;
>  cAsInt:=922337203685470000;
>  if Pint64(@c)^<>cAsInt then
>    WriteLn('Problematic CPU for Compiler'); // FPU error on machine 
> running the compiler Dbg stop point
>  writeln(c);
>  for ix:=1 to 9 do begin
>     c=c+0.0001    writeln(c);
> end;
>  readln;
> end.
> ==============================================
>
>
>
> To test :
>
> 1-Compile and run on your XP machine. Copy the .EXE to your W98 
> machine and run it. See the results.
Compiled on WinXP with FPC 2.6.4 (CPU Intel Core 2 Duo). Results:
 9.223372036854700000E+13
 9.223372036854700010E+13
 9.223372036854700020E+13
 9.223372036854700030E+13
 9.223372036854700040E+13
 9.223372036854700050E+13
 9.223372036854700060E+13
 9.223372036854700070E+13
 9.223372036854700080E+13
 9.223372036854700090E+13

When I run it on Win98 I get same result as  for WinXP (correct).

>
> 2-Compile and run on your Win98 machine. Copy the W98 .EXE to your XP 
> machine and run it. See the results.
Compiled on Win98 with FPC 2.6.4 (CPU Intel Pentium 4). Results:
Problematic CPU for Compiler
 9.223372036854699520E+13
 9.223372036854699530E+13
 9.223372036854699540E+13
 9.223372036854699550E+13
 9.223372036854699560E+13
 9.223372036854699570E+13
 9.223372036854699580E+13
 9.223372036854699590E+13
 9.223372036854699600E+13
 9.223372036854699610E+13

When I run it on WinXP I get same result as  for Win98 (incorrect).

BUT! When I try it (compile and run) on other computer with Win98 (old 
CPU Celeron) then results are correct as in step 1!!!

So what is your conclusion ?
I do not think, that culprit is CPU or Win98, but compiler on my PC with 
Win98 must be somehow confused by something else in my PC ... may be any 
DLL hell (does compiler links some external DLL (from system folder?) 
during compilation) ?

>
>
> I pop my stack and go back to what I was working on.
Thanks for your time.

-Laco.




More information about the fpc-pascal mailing list