Talk:Writing portable code regarding the processor architecture

From Free Pascal wiki
Jump to navigationJump to search

To keep the coherence of the Pascal language it would be better to change the size of Integer and Cardinal for 64 bits, as it happened when of the sprouting of Delphi 2 and as recommends Delphi 7 help: "The generic integer types are Integer and Cardinal; use these whenever possible, since they result in the best performance for the underlying CPU and operating system." In Delphi 1 Integer had 16 bits. The other integer types are called fundamental integer types (Shortint, Smallint, Longint, Int64, Byte, Word, and Longword) and they do not have to change of size between different compiler implementations. To facilitate the transition of codes of 32 for 64 bit it would be better to create new a directive one. For example: {$IntegerHas32bit ON} as interin solution. To complete it would be interesting to create a new type UInt64 instead of the strangers PtrInt and PtrUInt. Remembering that the 64 bit compiler cannot accept the construction longint(pointer(p)), but it must give to the message "Invalid type cast" --Wanderlan 15:42, 8 Feb 2005 (CET)

Ever tried sizeof(int) in C on 64 bit systems? On most 64 bit systems int is 32 bit. Simply because int is faster :) So PtrInt and PtrUInt are usefull. --FPK 16:04, 8 Feb 2005 (CET)

Saddly it does not have a decent standardization for Pascal, norms ISO 7185 and 10206 had not followed the evolution of the use of the Pascal and are omissive for this case! A valid way is the one that you are adopting, to use "C"isms or better "GCC"isms to evolve the language, particularly I think inelegant (ok, in truth, I think very ugly), but you are the architect :) Another one would be to follow an eventual Delphi 64, that nobody knows that standard will adopt. In this in case that it is easy to adjust the FPC in the future, it is enough to place this standard in directive {$Mode Delphi} ;} --Wanderlan 20:40, 8 Feb 2005 (CET)

I was with a doubt. The code:

  I64, J64: Int64;
  J64 := 0; 
  for I64 := 0 to MaxInt do inc(J64);

Is it slower than:

  I32, J32: Integer;
  J32 := 0; 
  for I32 := 0 to MaxInt do inc(J32);

In a AMD64 machine, using FPC for Linux64? How much? I do not have a AMD64 to test, snif...--Wanderlan 20:54, 8 Feb 2005 (CET)

In this case it won't matter much, but it gets slower as soon as data is blown up. Imagine an array[0..100000] of longint/int64;. The second requires simply the twice amount of memory and cause more memory traffic, cache polution etc. --FPK

You has reason! Microsoft confirms the way that you are adopting, using the same arguments, read these links:

Adopting this will be "easy" to convert FPC to Win64. --Wanderlan 14:04, 9 Feb 2005 (CET)