Pointer to function

Blitz3D Forums/Blitz3D Programming/Pointer to function

Grovesy(Posted 2005) [#1]
Hi all, I have a C background and use pointers all the time. I would like to know if pointers are possible in B3D? More inparticular I want to have a pointer to a function.

Is this possible?

Cheers


@rtur(Posted 2005) [#2]
No


octothorpe(Posted 2005) [#3]
Object() and Handle() let you reference and dereference objects and can be used similarly to pointers for some purposes.

You're stuck with dispatch functions, sorry.


Grovesy(Posted 2005) [#4]
I cannot find any information on Object() and Handle() in the B3D manual!!!


big10p(Posted 2005) [#5]
Object() and Handle() aren't officially supported. However, they are widely used by people.

Type MyType
  Field a,b,c
End Type

a.MyType = New MyType

; Get a unique integer ID for this type instance.
a_handle = Handle(a)

; Retrieve pointer to type instance associated with handle ID.
b.MyType = Object.MyType(a_handle)



Grovesy(Posted 2005) [#6]
OK cool, I understand that, but how would you use this to point to a function and call it? Whould something like this work?
;create handle
func_handle = Handle(add_numbers)

;use handle
andwer# = object.function(add_numbers(1, 2))

;function to be pointed to
function add_numbers#(a#,b#)
c# = a + b
return c
end function

cheers


Damien Sturdy(Posted 2005) [#7]
Like has been said, Function pointers are not possible.


big10p(Posted 2005) [#8]
Yep, function pointers are a sorely missed feature of Blitz3D - BMax has them but that's no help to us. :)

Object() and Handle() are for use with types only. I was just explaining how to use them as, like you say, they're not in the manual. Not sure why they were brought into the conversation, tbh - blame octothorpe. :P


octothorpe(Posted 2005) [#9]
Whoops :)

I thought I'd answer the more general question about whether or not any kind of pointers were possible. I should have been more explicit in stating that pointers to functions are not possible.