[fpc-pascal] Assigning pointer address

Tomas Hajny XHajT03 at hajny.biz
Mon Oct 1 10:51:42 CEST 2012

On Mon, October 1, 2012 10:43, dhkblaszyk at zeelandnet.nl wrote:


> I want to ask if casting an integer to a pointer is valid
> over all platforms. See below:
> p: PInteger;
> v: longint;
> [...]
> v :=
> 4235423;
> p := PInteger(v);
> Of course, the value of the pointer
> adress may vary, but in general is this a valid way to assign a pointer?
> Or will some platforms or architecture give problems?

Use PtrInt (signed) or PtrUInt (unsigned) types instead of longint, etc.
The former two are guaranteed to work for all architectures and platforms.
Your particular example fails on all 64-bit architectures (among others)


More information about the fpc-pascal mailing list