FAQ
I have a C struct that looks like this:

typedef struct {
ValueType type;
union {
bool boolean;
int32_t integer;
uint32_t uinteger;
double number;
char* cstring;
void* ptr;
};
} Value;

Where "ValueType" is an enum with 9 items. The first 5 types use the first
5 items in the union. The void* makes up the remaining "types".

For some reason I'm getting this in Go:

cgo: struct size calculation error off=37 bytesize=16

I've tried re-ordering the fields, and that doesn't seem to make a
difference. It shouldn't though - the struct should be 16 bytes on a 64bit
system. I'm not sure where 37 is coming from, but looking at the cgo
srouce, the two values should be equal, so "off" should be equal to 16.

Anyone know what is causing this?

Luke

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Kyle Lemons at Sep 5, 2013 at 2:35 am
    You wouldn't happen to be compiling on Mac OS X or some other llvm variant,
    would you?

    On Wed, Sep 4, 2013 at 7:04 PM, Luke Scott wrote:

    I have a C struct that looks like this:

    typedef struct {
    ValueType type;
    union {
    bool boolean;
    int32_t integer;
    uint32_t uinteger;
    double number;
    char* cstring;
    void* ptr;
    };
    } Value;

    Where "ValueType" is an enum with 9 items. The first 5 types use the first
    5 items in the union. The void* makes up the remaining "types".

    For some reason I'm getting this in Go:

    cgo: struct size calculation error off=37 bytesize=16

    I've tried re-ordering the fields, and that doesn't seem to make a
    difference. It shouldn't though - the struct should be 16 bytes on a 64bit
    system. I'm not sure where 37 is coming from, but looking at the cgo
    srouce, the two values should be equal, so "off" should be equal to 16.

    Anyone know what is causing this?

    Luke

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Luke Scott at Sep 5, 2013 at 2:55 am
    Yes, I'm using Mac OS X with the default gc compiler:

    go version devel +11b2294dca61 Wed Sep 04 17:02:08 2013 -0700 darwin/amd64
    On Wednesday, September 4, 2013 7:34:48 PM UTC-7, Kyle Lemons wrote:

    You wouldn't happen to be compiling on Mac OS X or some other llvm
    variant, would you?


    On Wed, Sep 4, 2013 at 7:04 PM, Luke Scott <lu...@visionlaunchers.com<javascript:>
    wrote:
    I have a C struct that looks like this:

    typedef struct {
    ValueType type;
    union {
    bool boolean;
    int32_t integer;
    uint32_t uinteger;
    double number;
    char* cstring;
    void* ptr;
    };
    } Value;

    Where "ValueType" is an enum with 9 items. The first 5 types use the
    first 5 items in the union. The void* makes up the remaining "types".

    For some reason I'm getting this in Go:

    cgo: struct size calculation error off=37 bytesize=16

    I've tried re-ordering the fields, and that doesn't seem to make a
    difference. It shouldn't though - the struct should be 16 bytes on a 64bit
    system. I'm not sure where 37 is coming from, but looking at the cgo
    srouce, the two values should be equal, so "off" should be equal to 16.

    Anyone know what is causing this?

    Luke

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Kyle Lemons at Sep 5, 2013 at 5:39 am

    On Wed, Sep 4, 2013 at 7:55 PM, Luke Scott wrote:

    Yes, I'm using Mac OS X with the default gc compiler:

    go version devel +11b2294dca61 Wed Sep 04 17:02:08 2013 -0700 darwin/amd64
    Yeah, I suspect it's another weirdness in the way llvm does DWARF-2 then.

    See golang.org/issue/3505 for when I ran afoul of this in libusb with
    flexible array members.

    On Wednesday, September 4, 2013 7:34:48 PM UTC-7, Kyle Lemons wrote:

    You wouldn't happen to be compiling on Mac OS X or some other llvm
    variant, would you?

    On Wed, Sep 4, 2013 at 7:04 PM, Luke Scott wrote:

    I have a C struct that looks like this:

    typedef struct {
    ValueType type;
    union {
    bool boolean;
    int32_t integer;
    uint32_t uinteger;
    double number;
    char* cstring;
    void* ptr;
    };
    } Value;

    Where "ValueType" is an enum with 9 items. The first 5 types use the
    first 5 items in the union. The void* makes up the remaining "types".

    For some reason I'm getting this in Go:

    cgo: struct size calculation error off=37 bytesize=16

    I've tried re-ordering the fields, and that doesn't seem to make a
    difference. It shouldn't though - the struct should be 16 bytes on a 64bit
    system. I'm not sure where 37 is coming from, but looking at the cgo
    srouce, the two values should be equal, so "off" should be equal to 16.

    Anyone know what is causing this?

    Luke

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 5, '13 at 2:04a
activeSep 5, '13 at 5:39a
posts4
users2
websitegolang.org

2 users in discussion

Luke Scott: 2 posts Kyle Lemons: 2 posts

People

Translate

site design / logo © 2021 Grokbase