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: Allow C code to use structures defined in Go #8114

Open
gopherbot opened this Issue May 28, 2014 · 1 comment

Comments

Projects
None yet
4 participants
@gopherbot

gopherbot commented May 28, 2014

by fuzxxl:

There are some C structures that cannot be correctly accessed from Go code as Go does
not provide the features needed to access them. Examples are unions, bitfields and
structures that are affected by issue #7560. Therefore, C code is needed to unmarshall
and marshall these structures into Go code.

Sadly, this is very uggly to do right now as there seems to be no sane way of having a C
function operate on types defined in Go code. Right now, I have to define the structure
I'm marshalling into on the C side of code which requires me to marshall the already
marshalled structure again if I want to provide that structure as an interface to other
packages.

Ideally, something like this is possible:

package example

/*
#include "go.h"

// struct I want to marshall
struct something {
    // ...
}

void marshall_something(struct something *s, GoSomething *g) {
    // unmarshall s into g
}
*/
import "C"

//export
type something struct {
    // corresponding Go type that is visible to C
    // ...
}
@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented May 28, 2014

Comment 1:

Labels changed: added repo-main, release-none.

@gopherbot gopherbot added new labels May 28, 2014

@bradfitz bradfitz removed the new label Dec 18, 2014

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment