You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I try to pass a C function pointer back to C from Go, I get a type error. It appears that cgo is mapping the function pointer type to *[0]byte (since there isn't a direct way to express C function-pointer types in the Go type system), but it isn't inserting the correct type conversions when referring to function-pointer values:
bcmills:~$ go build cgocallback
# cgocallback
src/cgocallback/main.go:17: cannot use _Cgo_ptr(_Cfpvar_fp_print_hello) (type unsafe.Pointer) as type *[0]byte in argument to _Cfunc_invoke
The workaround is to define a typedef for the function pointer type an explicitly convert to the typedef, but it would be nice if that workaround were not necessary.
package main
/*…typedef void (*closure)();*/import"C"funcmain() {
C.invoke(C.closure(C.print_hello))
}
bcmills:~$ go version
go version devel +2bbfa6f746 Thu Mar 9 15:36:43 2017 -0500 linux/amd64
The text was updated successfully, but these errors were encountered:
If I try to pass a C function pointer back to C from Go, I get a type error. It appears that cgo is mapping the function pointer type to
*[0]byte
(since there isn't a direct way to express C function-pointer types in the Go type system), but it isn't inserting the correct type conversions when referring to function-pointer values:cgocallback/main.go:
The workaround is to define a typedef for the function pointer type an explicitly convert to the typedef, but it would be nice if that workaround were not necessary.
The text was updated successfully, but these errors were encountered: