#1 2018-03-11 23:03:45

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,076
Website

Pointer arithmetic PByte and Pointer(PtrUInt(Dest)

I'm confused a little. In mORMot there are many places with a code like

Result := Pointer(PtrUInt(Dest)+bytesShift)

In this case FPC gives a hint "Conversion between ordinal and pointers is not portable", and "real" hints are lost between it.
I try to replace PtrUInt by PByte, this is more clear IMHO and FPC become happy, but in this case Delphi 7 fails to compile.
From other side, Delphi 7 know about PAnsiChar pointer arithmetic, so may be

Result := PAnsiChar(Dest)+bytesShift

is a solution? Or there is some hidden stones in this?

Offline

#2 2018-03-12 15:44:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 11,695
Website

Re: Pointer arithmetic PByte and Pointer(PtrUInt(Dest)

FPC is pessimistic about PtrUInt(Dest)+... since it will work seamlessly on i386 and x86-64 CPUs, and also ARM.
On some other targets (which don't support yet), it may be unsafe.

PAnsiChar(Dest) will make an hidden call to some RTL function is Dest is an AnsiString.
So it is not a silver bullet either.

Perhaps it may be safe to disable this particular hint for FPC (in Synopse.inc), in the scope of our units.

Offline

#3 2018-03-12 17:35:30

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,076
Website

Re: Pointer arithmetic PByte and Pointer(PtrUInt(Dest)

Thanks for explanation! If there is no silver bullet let's live with hints while we support Deplhy7. In case we (you) decide to stop support D7 in flavor of FPC we can replace it by PByte...

Offline

Board footer

Powered by FluxBB