using runtime cgo.Handle passing chan type

128 views
Skip to first unread message

Red

unread,
Dec 23, 2024, 11:29:44 AM12/23/24
to golang-nuts
Hi,
I need to use CGO to call a C function in a Go program, where the parameter type is a void pointer. Now I need to pass a struct to the C function, and the struct contains a channel. Additionally, I have a Go callback function that the C function will call, using the data from this struct. The problem is that when I try to access this struct in the Go callback function, I can't retrieve the data. Is this because it is not supported to pass a channel type to C?

The documentation I referred to:

https://pkg.go.dev/runtime/cgo#Handle
https://groups.google.com/g/golang-nuts/c/PLSIN5jmzpM/m/L9bYGl3oAQAJ

Ian Lance Taylor

unread,
Dec 23, 2024, 3:05:15 PM12/23/24
to Red, golang-nuts
You can pass a channel to C code using a cgo.Handle. I don't know
what you mean when you say "I can't retrieve the data." Can you show
a small self-contained example that demonstrates the problem?

Ian
Reply all
Reply to author
Forward
0 new messages