Pointers

BlitzMax Forums/BlitzMax Programming/Pointers

Bot Builder(Posted 2004) [#1]
Sorry, couldn't think of a better topic title. Anyway, I'm using pointers in some ways just fine. I have an array of them declared like this:
Global State:Float Ptr[]
Which is later initialized with the proper number of elements. This is all working fine. I'll read Floats in functions and return their values like this:
Function P5X:Float(P5Id:Int=0)
	Return State[P5Id][0]
EndFunction

Function P5Y:Float(P5Id:Int=0)
	Return State[P5Id][1]
EndFunction

Function P5Z:Float(P5Id:Int=0)
	Return State[P5Id][2]
EndFunction
This works fine. Here's the hard part though - some of the elements are integers, or bytes. For these I am attempting to do this:
Function P5Visible(P5Id:Int=0)
	Local v:Int Ptr=State[P5Id]
	Return v[48]
EndFunction
However, this brings up the error that you cannot convert from Float Ptr to Int Ptr. So, how am I supposed to read a different type of data? I could redefine the function that gets the pointer to the state data to return an Int or a Byte but this should be delt with anyway.


ImaginaryHuman(Posted 2004) [#2]
maybe declare Local v:int ptr=0 on its own line, then assign it v=State[p5Id]?


Dreamora(Posted 2004) [#3]
a simple explicit typecast could help ;)
* typecasts are done using type() *

Function P5Visible(P5Id:Int=0)
	Local v:Int Ptr=Int Ptr(State[P5Id])
	Return v[48]
EndFunction



Bot Builder(Posted 2004) [#4]
Ah. Didn't know that blitz had explicit castes since most of its all implicit :) There'd be no danger, imho of implicitly casting pointer 'types' so that other pointers of different type point at the same thing.

Anyway, now it compiles :)