Serguei TARASSOV wrote on Thu, 03 Mar 2016:

Jeppe Johansen-3 wrote

The Integer type depends on what compiler mode you are in, and what
operating system. Sometimes it's 32bit and other times it's 16bit.

AFAIK it only depends on the compiler mode.

It was FPC 2.6.4 64 bits in FPC mode on Linux. See the sources to reproduce.
Change:
TicketsCount: longint;
to
TicketsCount: integer;

Compile: fpc -O2 -Cr- HappyTickets.pas

Result: Found 31902 tickets. Elapsed time, msec: 203

I don't see any reason to use 16-bits integer in this code much less in
64-bits mode.

The reason is, as always, compatibility. FPC mode started as an extension of the Turbo Pascal compatibility mode. In Turbo Pascal, integer is 16 bits. In Delphi, it's 32 bits, so both in Delphi and in ObjFPC modes, integer is 32 bits. Code that was written with integer = 16 bits may no longer work the same if the size of the integer type is changed to 32 bits (especially if overflow checking is off).

I don't test it yet in FPC 3.0 bit 3.0 has other problems with my test:
- changing the type of n1-n8 from 0..9 to longint increases the time by 10%
- changing the type of n1-n8 from 0..9 to integer doubles the time!

On the contrary, in Delphi 10 changing the type of n1-n8 from 0..9 to
integer decreases the time by 60%

If you want to compare with Delphi, it's better to compile the program in Delphi mode. You should see the same 10% increase in FPC that you see when you change it to longint.


Jonas
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to