Recent

Author Topic: PtrInt, SizeInt, NativeInt  (Read 2721 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1461
    • http://wiki.lazarus.freepascal.org/User:Zoran
PtrInt, SizeInt, NativeInt
« on: July 07, 2016, 01:22:57 pm »
As I understand, PtrInt and SizeInt are signed integer types which have the size of pointer (size of memory address) of target architecture, so on 32-bit system, they are same as LongInt, and on 64-bit they are same as Int64.

They are always same, aren't they? My question is - is there a reason why we have two types? Aren't they intended for same purpose?

I know there is also NativeInt, which is added because Delphi has this type for same purpose, since they introduced 64-bit support, which happened several years later than FPC.

So, I understand why NativeInt is added to FPC, but I would like to know if there is a reason why we have both SizeInt and PtrInt?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 669
Re: PtrInt, SizeInt, NativeInt
« Reply #1 on: July 07, 2016, 01:34:09 pm »
sizeint corresponds to the size of the "offset" part of pointers, while ptrint to the size of an entire pointer. On most platforms these are the same because they use a linear address space, but e.g. on 16 bit MSDOS with a memory model that supports far data, sizeint is 16 bit while ptrint is 32 bit (16 bit segment + 16 bit offset).

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7494
Re: PtrInt, SizeInt, NativeInt
« Reply #2 on: July 07, 2016, 02:01:21 pm »
A different wording of of the sizeint definition might be: sizeint is an integer that can hold the maximum (positive) difference between two pointers within the same allocation.


Zoran

  • Hero Member
  • *****
  • Posts: 1461
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: PtrInt, SizeInt, NativeInt
« Reply #3 on: July 07, 2016, 02:28:43 pm »
Thank you, Jonas and Marco.