How do I print a function pointer?

BlitzMax Forums/BlitzMax Beginners Area/How do I print a function pointer?

ImaginaryHuman(Posted 2005) [#1]
The title sums it up really. How do you print a function pointer stored in a function-pointer variable?

I tried various combinations of Int() Int Ptr() Byte Ptr() VarPtr() [0] etc trying to get it to the right thing but no luck.


ImaginaryHuman(Posted 2005) [#2]
I even tried this:

Local myfunt()=Null
Local mybank:TBank=CreateStaticBank(Byte Ptr(VarPtr(myfunct)),4)
Print String(PeekInt(mybank,0))

... not this exact code, but something to the same effect, but regardless of always setting the pointer to Null, it always contains a value. I have no idea what's going on.

How can I print a function pointer without calling the function or causing compiler errors?

(yes you might want to move this thread out of the beginners area now that I mentioned PeekInt ;-))


Bot Builder(Posted 2005) [#3]
uh, with VarPtr() you are creating a pointer to the function pointer. So, yes, it would make sense that this would be a non-null pointer. try taking out the VarPtr()?


marksibly(Posted 2005) [#4]
Local my_fun()

Print Int( Byte Ptr my_fun )

The reason it's non-null is because a null function pointer actually points to an internal function that generates a null function error.


ImaginaryHuman(Posted 2005) [#5]
Ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh! Thanks Mark. So a null function pointer isn't 0, it's the address of some `Null()` function. I guess that makes sense, since 0 could be a valid address.

Thanks.

And I guess it's okay that a Null function pointer is, for example, 1354095, since that memory location wont be occupied by anything else other than the Null function. Makes sense.

So Null integers etc are 0, but just the function pointers point to the Null function? I guess that makes sense too because functionpointer()=Null is like assigning the function pointer to the Null() function.

Doh! Thanks