Int vs Byte Ptr

BlitzMax Forums/BlitzMax Programming/Int vs Byte Ptr

KronosUK(Posted 2014) [#1]
Can someone please explain to me how some wrappers use byte ptr to reference an object and others just use an Int value. Not an int ptr but an int.

Using ints seems easier but I have no idea how to set that up.


Brucey(Posted 2014) [#2]
With 32-bit addressing, a pointer is 4 bytes, the same as an Int. So in the current BlitzMax, it is safe enough to assume that any pointers are in fact the same size as an Int.

Of course, if 64-bit ever arrived, all that existing code would break ;-)


KronosUK(Posted 2014) [#3]
that seems simple. thanks


Yasha(Posted 2014) [#4]
One minor advantage of Byte Ptr over Int is that even if the value itself is the same, it makes it clearer to both the compiler and any human readers (especially yourself, if you wrote something "clever" six months ago) what your intentions are for the value. A Byte Ptr can be added and subtracted and nothing else, without either manual casting, or passing it to an external function.

It's a little hollow to talk of "safety" when the language lets you use unrestricted casts, but it is a small bonus and it does help when the pointer-play starts getting complicated (e.g. if you need to cast through two or more layers of indirection, it's really handy to have the compiler telling you "actually you need one more layer before you get the Int you want", or similar).