Skip to content

cmd/cgo: reject C structs with Go-incompatible field alignment #7560

Closed
@gopherbot

Description

@gopherbot

by dturnbull:

go version go1.2.1 darwin/amd64
Apple LLVM version 5.0 (clang-500.2.79)

Using this program:

package main
/*
#include "stdlib.h"
#include "stdint.h"
#include "complex.h"
typedef struct {
    uint32_t unalign;
    float complex osc;
} mixer;
mixer* Mixer() {
    mixer *o = malloc(sizeof(mixer));
    o->osc = (3.0 + 5.0*I);
    return o;
}
*/
import "C"
import "fmt"
func main() {
    o := C.Mixer()
    fmt.Println(o)
}

I get incorrect output:
&{0 (5+0i)}

Removing the unalign element or changing to a double complex gives the expected output:
&{(3+5i)}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions