I have a struct in C lib with some callbacks defined inside it. Problem that Go treat this fields as *[0]byte array type and I can't set it to pointer:
./test.go:16: cannot use _Cgo_ptr(_Cfpvar_fp_cb_func) (type unsafe.Pointer) as type *[0]byte in assignment
Sample of problem code:
package main
/*
void cb_func();
typedef struct cb_s {
void (*cb_f)();
} cb_s;
*/
import "C"
//export cb_func
func cb_func() {}
func main() {
var x C.struct_cb_s
// here I want to set callback cb_f to pointer of cb_func().
x.cb_f = C.cb_func
}
One possible solution - write a C setter, something like this:
void cb_set(cb_s *s) {
s->cb_f = &cb_func;
}
but it looks ugly: I can't pass cb_func as argument to setter (already tried cb_set(cb_s *s, void(*func)()), but got the same error about *[0]byte) and have many similar callbacks, so need to write setter for each pair of callback - callback function.
Any other solutions?