Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which one i should use to do 64-bit pointer math for Delphi,, NativeUInt or NativeInt

Since there is 64-bit delphi compiler, we should use 64-bit pointers.

so wondering any difference if we use nativeint or nativeuint. for example,

Should I use

Pointer(NativeUInt(Pointer(Buffer)) + LongWord(datawrote))^,

or

Pointer(NativeInt(Pointer(Buffer)) + LongWord(datawrote))^,

Does it matter? which is better style?

like image 209
justyy Avatar asked Jun 27 '14 13:06

justyy


1 Answers

The simplest thing to do is cast the pointer to PByte. Then you can perform arithmetic on that:

PByte(Buffer) + offset

That expression is of type PByte and so you may need to cast it back to some other pointer type.

As a general rule, pointers are not integers and you should resist the temptation to convert cast them to be integers. It is almost always best to let pointers be pointers. You can always perform pointer arithmetic on PAnsiChar, PWideChar and PByte, and for other pointer types you can use {$POINTERMATH ON} to enable pointer arithmetic.

like image 66
David Heffernan Avatar answered Oct 27 '22 20:10

David Heffernan