Skip to content
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
Open

cmd/cgo: Allow C code to use structures defined in Go #8114

gopherbot opened this issue May 28, 2014 · 1 comment
Milestone

Comments

@gopherbot
Copy link

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
Copy link
Contributor

Comment 1:

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

@bradfitz bradfitz removed the new label Dec 18, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants