Skip to content

Fields missing from cgo structures when #pragma(pack) is used. #8110

@gopherbot

Description

@gopherbot

by fuzxxl:

The following code works under Go 1.2 but fails to compile with the most recent go tip
(4b3cdcb02f2d).

package cgotest

/*
#pragma pack(1)
struct foo {
    char c;
    int x;
};
*/
import "C"
import "unsafe"

func foo(f *C.struct_foo) int {
    return int(f.x)
}

This is what the correspond _cgo_type.go looks like:

type _Ctype_char int8
type _Ctype_int int32

type _Ctype_struct_foo struct {
        c       _Ctype_char
        _       [4]byte
}

In Go 1.2, the type definition used to have the x field instead of an underscore. This
looks like a regression to me.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions