What version of Go are you using? Using Go 1.1.2, cgo seems to produce the expected output.
I ran go tool cgo main.go
, and the generated _obj/_cgo_gotypes.go
file contained the following definitions:
type _Ctype_param_struct_t _Ctype_struct_param_struct_t
type _Ctype_struct___0 struct {
//line :1
c _Ctype_int
//line :1
d _Ctype_int
//line :1
}
type _Ctype_struct___1 struct {
//line :1
f _Ctype_int
//line :1
g _Ctype_int
//line :1
}
type _Ctype_struct_param_struct_t struct {
//line :1
a _Ctype_int
//line :1
b _Ctype_int
//line :1
anon _Ctype_struct___0
//line :1
e _Ctype_int
//line :1
anon2 _Ctype_struct___1
//line :1
}
When I modified your program to correctly refr to c
and d
nested in the anon
field and uncommented the other statements, the program compiled and ran with the final statement printing the struct as.
main._Ctype_param_struct_t{a:0, b:0, anon:main._Ctype_struct___0{c:0, d:0}, e:0, anon2:main._Ctype_struct___1{f:0, g:0}}
If you are using an older version of Go, perhaps try upgrading. You could also try running cgo
manually like I did to see what it is generating if you still run into problems.