[fpc-devel] Warning: Conversion between ordinals and pointers is not portable

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Dec 6 14:16:47 CET 2012

On 06 Dec 2012, at 14:03, Martin wrote:

> Yet what I do not understand, is why I get that message as warning  
> (as opposed to a hint). If I understand it right (I have not tested,  
> maybe it gives a warning on 64 bit target too, if so ignore the  
> rest), and I compile for  a 64bit target, then it downgrades to a  
> hint again?

Yes. If you typecast an integer to a pointer and both have the same  
size, you get a hint. If they have a different size, you get a warning.

> The only difference is, that in the above example, if compiled for a  
> 32 bit system, I already may have broken code. But then what it  
> actually means is that I should get warning about  a truncating the  
> value.
>  b := byte(a);
> Gives no warning at all.

That's because truncating integers cannot result in invalid addresses.  
The warning was added to help people moving from 32 bit to 64 bit  
systems and using longint typecasts in their programs to convert  
between addresses and integers. There are very few cases whereby  
discarding the upper 32 bit of a pointer is intended or results in  
valid code.

> It also truncates the warning. What is then special about  
> potentially truncating a value by using pointer(a)? If "pointer(a)"  
> is worth a warning (instead of a hint, why isn't byte(a)?

Because there never was a migration from a system whereby int64 was  
the same size as a byte and now it isn't anymore, and there are many  
common cases whereby discarding part of an integer value is part of an  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20121206/7410e675/attachment.html>

More information about the fpc-devel mailing list