PtrInt is Int64. Isn't Integer also 64 bit? So why the range check error here?Not even by a longshot. For details See ordinal types (https://www.freepascal.org/docs-html/ref/refsu4.html):
The integer type maps to the smallint type in the default Free Pascal mode. It maps to either a longint in either Delphi or ObjFPC mode. The cardinal type is currently always mapped to the longword type.
Ptrint is a signed integer type which has always the same size as a pointer. Ptrint is considered harmfull and should almost never be used in actual code, because pointers are normally unsigned.
PtrInt - Signed integer type with same size as Pointer.That does not necessarily means 64 bit. Therefor the size depends on the target the code was compiled for.
For details See ordinal types (https://www.freepascal.org/docs-html/ref/refsu4.html):I did and it 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.
The result should be NativeInt. As per my example.For details See ordinal types (https://www.freepascal.org/docs-html/ref/refsu4.html):I did and it says:QuoteEvery 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.
So function Result should be SizeInt here and not Integer, right?
And also: Test for 64bit should be done with 4GB of used memory to detect things like this.
You can check the actual size of the type integer with a simple check:For details See ordinal types (https://www.freepascal.org/docs-html/ref/refsu4.html):I did and it says:QuoteEvery 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.
WriteLn(SizeOf(integer));
It will write out the actual number of bytes that the integer type occupies.So function Result should be SizeInt here and not Integer, right?Just like Thaddy i would also prefer/opt for NativeInt, although in theory you could perhaps also use SizeInt. Tbh i do not know all targets from heart, so that might pose a problem for some of them.
No you don't need to test this with 4 GB of actual memory.
Just use my code and it will work on any (well, actually, most, there are some exotic exceptions) platform.
Maybe PtrInt would be best (see systemh.inc):QuoteSo function Result should be SizeInt here and not Integer, right?Just like Thaddy i would also prefer/opt for NativeInt, although in theory you could perhaps also use SizeInt. Tbh i do not know all targets from heart, so that might pose a problem for some of them.
Sorry, didn't see new posts while replying.As can been seen we're in each other hairs all along, so please feel free to join the club :)
This code is not mine it's SynEdit's code.In that case do realize that even though the code is perhaps wrong for your shown example code, that it might have been declared this way on purpose. Might be for legacy/compatibility reasons, might even be because rest of the code does not know how to handle the result (correctly) if larger then integer.
Well what you try to measure is distance.No, it's a compare function and if all aspects of the types are identical a "fallback" is to compare the pointers directly.