|CGo unexported types||dpx.in...@gmail.com||11/26/12 10:37 AM|
I asked this question on stackoverflow and still didn't get definite answer, so I decided to try here. Text below mostly is copied from the stackoverflow question.
Suppose there is CGo package with a struct defined like this:
Now suppose that from somewhere else I get
Do I understand correctly that there is completely no way to create new
Attempting to use something like
Some background: I need a way to create such structure when I use
A piece of code I'm trying to fix: https://gist.github.com/4141343
|Re: [go-nuts] CGo unexported types||Ian Lance Taylor||11/26/12 12:11 PM|
On Mon, Nov 26, 2012 at 10:37 AM, <dpx.in...@gmail.com> wrote:Other than using the unsafe package to push things through pointers, I
believe that is correct.
If that is a reasonable thing to do, then one would hope that the
go-gtk package would provide a way to do it. I don't know enough
about gtk to know how reasonable it is.
|Re: [go-nuts] CGo unexported types||dpx.in...@gmail.com||11/26/12 2:07 PM|
Thank you for your answer. At least now I certainly know this is hard)
Could you please explain how to do this? I have tried (see stackoverflow question and answer) playing with unsafe pointers but couldn't manage to do it. I don't know how to beat type system to somehow accept unsafe pointer as standard pointer to C struct provided C struct is defined in another package.
вторник, 27 ноября 2012 г., 0:11:22 UTC+4 пользователь Ian Lance Taylor написал:
|Re: [go-nuts] CGo unexported types||Ian Lance Taylor||11/26/12 3:46 PM|
On Mon, Nov 26, 2012 at 2:07 PM, <dpx.in...@gmail.com> wrote:Untested:
// Assume u is the pointer I want to store. Presumably it was
obtained from C code in some way.
var t test.Test
p := (*unsafe.Pointer)(unsafe.Pointer(&t.Field))
*p = unsafe.Pointer(u)
|Re: [go-nuts] CGo unexported types||dpx.in...@gmail.com||11/27/12 1:01 AM|
Yeah, this seem to work! Thank you very much!
вторник, 27 ноября 2012 г., 3:46:44 UTC+4 пользователь Ian Lance Taylor написал: