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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With