Recent

Author Topic: documentation ptrint, nativeint  (Read 2038 times)

BobS

  • Full Member
  • ***
  • Posts: 153
documentation ptrint, nativeint
« on: June 14, 2019, 07:10:13 am »
The documentation says ptrint alias should not be used, but nativeint just aliases to ptrint.  It says it's there for Delphi compatibility, but if Delphi has some workaround to avoid this problem (i.e. it's really using unsigned) shouldn't FP or if Delphi has the same problem then shouldn't the documentation have the warning also under nativeint?  Not a big deal, of course just wondering.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: documentation ptrint, nativeint
« Reply #1 on: June 14, 2019, 07:47:39 am »
The documentation says ptrint alias should not be used, but nativeint just aliases to ptrint.  It says it's there for Delphi compatibility, but if Delphi has some workaround to avoid this problem (i.e. it's really using unsigned) shouldn't FP or if Delphi has the same problem then shouldn't the documentation have the warning also under nativeint?  Not a big deal, of course just wondering.
The documentation says this: https://www.freepascal.org/docs-html/rtl/system/ptrint.html so its introduction was more or less a mistake
You should use  ptrUint and family  on pointer types , which is also compatible with some Delphi versions. 
We also have  UintPtr, an alias for the PtrUInt type for compatibility with newer Delphi versions.

Any warning is about using signed integers for pointers.
There should not be a warning for NativeInt, because that is a legal type on its own and not a pointer.

BTW: Older Delphi's really have no workaround: it simply means that you only have half the addressable space -32 bit 2GB - (the positive part up to max(ptrInt) instead of the full unsigned range- 32bit 4GB -.
« Last Edit: June 14, 2019, 08:14:14 am by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: documentation ptrint, nativeint
« Reply #2 on: June 14, 2019, 10:12:14 am »
Sorry, Thaddy, I can't make sense of that. Ptrint and intptr are not pointers either since they are aliases?

The point is indeed unsigned. But for FPC the ptrint type is the oldest and thus core type, so it is documented there.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: documentation ptrint, nativeint
« Reply #3 on: June 14, 2019, 11:13:33 am »
Sorry, Thaddy, I can't make sense of that.
The point is indeed unsigned. But for FPC the ptrint type is the oldest and thus core type, so it is documented there.
I was not complete it seems.
Specialize a type, not a var.

BobS

  • Full Member
  • ***
  • Posts: 153
Re: documentation ptrint, nativeint
« Reply #4 on: June 14, 2019, 12:03:33 pm »

Any warning is about using signed integers for pointers.
There should not be a warning for NativeInt, because that is a legal type on its own and not a pointer.

According the RTL (chm version) documentation NativeInt is "Alias for PrtInt" and this is given as the definition:

type NativeInt = PtrInt

Description

NativeInt is defined for Delphi compatibility. It is a signed integer with the size of a pointer, so 32-bit on 32-bit platforms, 64-bit on 64-bit platforms.

So if this is correct it should cause the same overflow error in the ptrint example.  Now obliviously it is best to just ptruint, but again seems like there needs to be a warning in the doc.  Or am I still not getting it?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: documentation ptrint, nativeint
« Reply #5 on: June 14, 2019, 12:30:57 pm »
Well, it is an alias for ptrint, which has the full doc for the type. I added an one line warning.

BobS

  • Full Member
  • ***
  • Posts: 153
Re: documentation ptrint, nativeint
« Reply #6 on: June 14, 2019, 12:34:57 pm »
Thanks, when you're in a hurry you don't always remember to check the links  ;) .

 

TinyPortal © 2005-2018