[fpc-pascal] Platform Dependent Integer Types

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Apr 6 23:50:01 CEST 2017


On Thu, 6 Apr 2017 18:25:40 -0300
African Wild Dog <paintedlycaon at gmail.com> wrote:

> Which integer types have their size dependent on platform?
> E.g. in Delphi, LongInt can 32 or 64 bits depending on the platform.

Why do you think that Delphi's longint has 64bits anywhere?
Delphi's NativeInt is 32 or 64bit depending on platform.


> The documentation says "every platform has a ”native” integer size,
> depending on whether the platform is 8-bit, 16-bit, 32-bit or 64-bit. e.g.
> On AVR this is 8-bit. ", but it is not clear about which integer types are
> "natives".

Most of FPC's integer types defined via IFDFEs. See
fpc/rtl/inc/systemh.inc
You can use Lazarus' Find Declaration on any type and see the
definition. 
For example:

{$ifdef CPU64}
  SizeInt = Int64;
  SizeUInt = QWord;
  PtrInt = Int64;
  PtrUInt = QWord;
  ValSInt = int64;
  ValUInt = qword;
  CodePointer = Pointer;
  CodePtrInt = PtrInt;
  CodePtrUInt = PtrUInt;
{$endif CPU64}

{$ifdef CPU32}
  SizeInt = Longint;
  SizeUInt = DWord;
  PtrInt = Longint;
  PtrUInt = DWord;
  ValSInt = Longint;
  ValUInt = Cardinal;
  CodePointer = Pointer;
  CodePtrInt = PtrInt;
  CodePtrUInt = PtrUInt;
{$endif CPU32}


  { NativeInt and NativeUInt are Delphi compatibility types. Even though Delphi
    has IntPtr and UIntPtr, the Delphi documentation for NativeInt states that
    'The size of NativeInt is equivalent to the size of the pointer on the
    current platform'. Because of the misleading names, these types shouldn't be
    used in the FPC RTL. Note that on i8086 their size changes between 16-bit
    and 32-bit according to the memory model, so they're not really a 'native
    int' type there at all. }
  NativeInt  = PtrInt;
  NativeUInt = PtrUInt;


Mattias



More information about the fpc-pascal mailing list