Pointers
BlitzMax Forums/BlitzMax Programming/Pointers
| ||
Playing around with pointers, why wont this work. Can pointers only be basic object types? e.g. int, float, etc. Is it not possible to create a type ptr?Type test End Type Local t:test = New test Local p:test Ptr = Varptr t This seems to work, but is it the only way? Type test Field i:Int = 100 End Type Local t:test = New test t.i = 10 Local p:Int Ptr Local i = HandleFromObject(t) p = Varptr i Local n:test = test(HandleToObject(p[0])) Print n.i |
| ||
Varptr has to have the () in order to return a value, ie local p:test ptr=varptr(t) |
| ||
It still says "Illegal Pointer Type" on the last line of the first example. I was more wondering why you cant have pointers to Blitzmax types. I've settled for using a TList and dumping the result to an array and indexing the array just like you would a traditional C pointer. Seems to work well without the overhead of the TList when reading results back. |
| ||
The reason you can't have a pointer to a Blitzmax type is because Blitzmax types are already "by reference." So, if you want p to be a pointer to t, you can do the following global t:test = new test global p:test = t '<---p now points to the same object as t Any changes made to p are of course reflected in t, and the opposite is true as well. |