#fn ptr with state

1 messages · Page 1 of 1 (latest)

steel moon
#

i need a function which takes an allocator and will return a function pointer (the function is supposed to access the allocator). unfortunately i get a compile error, i need a workaround, is there any way?

empty valley
#

the new returned function needs the allocator? if so use a struct

copper nimbus
#

bundle your fn pointer with a struct with the state it needs, then pass the state as a parameter(s) to the fn when calling it.

steel moon
#

the new function allocates but it's a function ptr being called by C code

copper nimbus
#

the c code should provide a way to pass your own data, usually via a type erased pointer.
if ti doesnt its a bad c lib, you'd have to use a global to get around it.

steel moon
#

i think it does, ill try looking into that and return