Pointer to function

Blitz3D Forums/Blitz3D Programming/Pointer to function

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

No

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.

I cannot find any information on Object() and Handle() in the B3D manual!!!

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)


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

Like has been said, Function pointers are not possible.

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

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.