Skip to content

Cannot assign strut to interface type of another package when interface type uses C types #20534

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

Closed
AlexRouSg opened this issue May 31, 2017 · 4 comments

Comments

@AlexRouSg
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.8.1 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/chotepud/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build397619697=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

package a

import "C"

type interface foo {
    bar() C.Uint32
}
package b

import "C"
import "a"

type struct foo {}
var asdf a.foo = &foo{}

func (*foo) bar() C.Uint32 {
}

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

Code compiles

What did you see instead?

cannot use software literal (type *foo) as type a.foo in assignment:
*software does not implement a.foo (wrong type for bar method)
have bar() C.Uint32
want bar() a.C.Uint32

@AlexRouSg
Copy link
Contributor Author

Am I not supposed to pass C types between packages?

@AlexRouSg AlexRouSg changed the title Cannot assign strut to interface type of another package when interface type uses certain C types Cannot assign strut to interface type of another package when interface type uses C types May 31, 2017
@dominikh
Copy link
Member

Cgo translates C types into equivalent unexported Go types. Because the translations are unexported, a Go package should not expose C types in its exported API: a C type used in one Go package is different from the same C type used in another.

(from https://golang.org/cmd/cgo/)

As far as I can tell, this is working as intended.

@AlexRouSg
Copy link
Contributor Author

Guess I should've read the docs more carefully ....
Was there any post explaining why?

@ianlancetaylor
Copy link
Contributor

Dup of #13467 , which discusses why cgo works the way it does.

@golang golang locked and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants