CGo: How to get a pointer to a C function?

Written by
Link to Post

https://www.reddit.com/r/golang/comments/bzonbk/cgo_how_to_get_a_pointer_to_a_c_function/ by 

Hi, there’s a C library which has a function, say foo() that takes a pointer to a function (a C function, naturally) as one of the arguments. In the same library there’s a function bar() address of which I need to pass to foo(). Can this be done from Go? So far I wasn’t able to do this since CGo wraps imported C functions in stub functions (which perform checks, calling convetion conversion, etc.). Obviously if I pass the address of the CGo wrapper of bar(), it won’t work.

How do I get the pointer to the C function itself? So far I tried some go:linkname tricks but that doesn’t seem to cut it.

Thanks!

submitted by /u/theOtherOtherBob
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply