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

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


On 02 Dec 2012, at 22:26, Martin wrote:

> If compiled, with PtrUint (as is below)
>
> Free Pascal Compiler version 2.6.0 [2012/01/04] for i386
> Compiling C:\Users\martin\AppData\Local\Temp\project1.lpr
> project1.lpr(11,28) Warning: Variable "p" does not seem to be  
> initialized
> project1.lpr(11,11) Warning: Conversion between ordinals and  
> pointers is not portable
> project1.lpr(9,5) Note: Local variable "darr" is assigned but never  
> used
> Linking C:\Users\martin\AppData\Local\Temp\project1.exe

That's because cardinal-cardinal results in an int64, because of a.o. http://bugs.freepascal.org/view.php?id=8321

> If replace the type
> type IPointer = PtrInt;
>
> Free Pascal Compiler version 2.6.0 [2012/01/04] for i386
> Compiling C:\Users\martin\AppData\Local\Temp\project1.lpr
> project1.lpr(11,28) Warning: Variable "p" does not seem to be  
> initialized
> project1.lpr(11,11) Hint: Conversion between ordinals and pointers  
> is not portable
> project1.lpr(9,5) Note: Local variable "darr" is assigned but never  
> used
> Linking C:\Users\martin\AppData\Local\Temp\project1.exe
>
> So actually the message is just downgraded from Warning to Hint.

Yes, that's by design. The compiler has no special knowledge about the  
ptrint or ptruint types. It is almost impossible to fix all hints for  
non-trivial programs, and they only exist to help find possibly  
suspicious locations in code (and typecasting an integer into a  
pointer is such an expression). You can always disable a particular  
hint with -vqXXX if you are not interested in it.

> and the full command line as issued by Lazarus:
> fpc.exe  -MObjFPC -Scghi -O1 -gw2 -godwarfsets -gl -gh -vewnhi -Filib 
> \i386-win32  -FUlib\i386-win32\ -l C:\Users\martin\AppData\Local\Temp 
> \project1.lpr"
>
> If I remove the " - PointerSize2" it is always a hint. But the  
> location (11,11) doe not point to thin, it points to the uppercase  
> "P" of this most outer "Pointer()"typecast

The typecast of the integer expression to a pointer is what triggers  
the warning/hint.


Jonas



More information about the fpc-devel mailing list