[fpc-pascal] Conversion between ordinals and pointers is not portable

Tomas Hajny XHajT03 at hajny.biz
Wed Mar 2 10:35:19 CET 2011

On Wed, March 2, 2011 09:02, Roland Turcan wrote:


> I have this code:
>   p := PByteArray (PtrUInt (@FData.Content[0]) + MOffset);
>   ...
> But the compiler informs about %subj%.
> How to get rid of this warning and to make code portable?

At least with 2.4.2 it is not a warning but just a hint. You should not
try to avoid all the hints, but they may be useful when trying to find out
source of some issues.

One concrete comment would be that MOffset is an integer and thus result
of the addition is an int64 (as also pointed out by another hint). This
means that you in fact typecast an int64 value to a pointer. That is
always a valid operation on 64-bit platforms but on 32-bit ones it may
potentially overflow depending on the values of MOffset and @FData.
Obviously, this should never happen if you use the 'right' values of
MOffset (and if not, it's equally dangerous on 32-bit or 64-bit regardless
of overflows anyway ;-) ) but the compiler cannot really check that.


More information about the fpc-pascal mailing list