FAQ
I have been a little confused since the new cgo pointer argument
restrictions for go1.6 were announced about what the final verdict was
regarding passing functions pointers to C, so they may be used as a
callback in an event-driven system. For example, I understand that GUI
toolkits like GTK require many callbacks to be set for handling to user
events.

Is it possible for these systems to be integrated in Go? When is it
acceptable to pass a function pointer to C, and for C to store that pointer
for future use?

Naively it seems intuitive to me that passing closures can trivialaly
violate the pointer passing restrictions (by closing over variables
pointing to Go memory). But if I have exported a static function from Go
(exported to C using `//export myFunc`). Then can I pass that a pointer to
the exported function to cgo? A slight variant of this question would be,
can I pass a pointer to a C function which calls a static Go function that
was exported by my application?

Of course C is not supposed to store Go pointers according to the new
restrictions, so really it is just unclear to me when pointers to static
functions are actually "Go pointers" (using the specific terminology of the
cgo specification, pointers pointing to memory allocated/managed by the Go
runtime?).

I would really appreciate it if anyone could help shed light on this for
me. Thanks for the help.

Cheers

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 30, '16 at 1:53a
activeMar 30, '16 at 3:07a
posts5
users2
websitegolang.org

2 users in discussion

Bryan Matsuo: 3 posts Ian Lance Taylor: 2 posts

People

Translate

site design / logo © 2021 Grokbase