-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: C struct bitfield is omitted #29611
Comments
Yes, the cgo behavior has changed, but why is this a bug? You can't refer to the bitfield either way. The type alignments mean that the fields will continue to be at the correct offsets. |
var st C.MyStruct
C.fill_my_struct(&st) Size of |
Try printing out the sizes and field offsets using the reflect package. They should be the same as the C sizes and offsets available using C |
Sorry, I mis-read description in this issue. What I expected is cgo generate |
Yes, you are correct - the sizes and offsets are the same. The main source of confusion was a difference in number of fields reported with: var s C.struct_foobar
t := reflect.TypeOf(s)
for i := 0; i < t.NumField(); i++ {
fmt.Println(i, ":", t.Field(i), ",", t.Field(i).Offset)
}
// go1.11.4
// 0 : {a main main._Ctype_uchar 0 [0] false} , 0
// 1 : {d main [3]main._Ctype_ushort 2 [1] false} , 2
// go1.11.3
// 0 : {a main main._Ctype_uchar 0 [0] false} , 0
// 1 : {_ main [1]uint8 1 [1] false} , 1
// 2 : {d main [3]main._Ctype_ushort 2 [2] false} , 2 Thanks. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
When compiled with
go version go1.11.3 linux/amd64
, the underlyingfoobar
representation is the following:What did you see instead?
When compiled with
go version go1.11.4 linux/amd64
, thefoobar
's second field (bitfield) is omitted:The text was updated successfully, but these errors were encountered: