You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following code which compiled in 1.8.x and 1.9.x:
import "C"
func setValue(to interface{}, from interface{}) {
switch to.(type) {
case *C.size_t:
t := to.(*C.size_t)
f := from.(int)
*t = C.size_t(f)
case *C.ulong:
t := to.(*C.ulong)
f := from.(int)
*t = C.ulong(f)
default:
panic("Invalid type in command line parameter")
}
}
func main() {
someVal := 3
var someUlong C.ulong
var someSizeT C.size_t
setValue(&someUlong, someVal)
setValue(&someSizeT, someVal)
}
What did you expect to see?
Proper compilation, switch is able to determine if interface is a *C.size_t or *C.ulong.
What did you see instead?
./main.go:12: duplicate case *_Ctype_ulong in type switch
previous case at ./main.go:8
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
cgo: as of Go 1.10 it seems pointers to C.size_t or C.ulong are treated as the same type
cmd/cgo: as of Go 1.10 it seems pointers to C.size_t or C.ulong are treated as the same type
Mar 2, 2018
It's not obvious to me that this is fixable. C is not Go. C types are not Go types. In C, unlike Go, a typedef does not introduce a new type. In some implementations of C, size_t and unsigned long really are the exact same type. It has two names but it's the same type. On such an implementation, if we pretend that C.size_t and C.ulong are different types, then we will wind up forbidding calls to C functions that according to the C type rules should be permitted. That would not be a good experience.
No worries, I just wanted to confirm that this wasn't something I was doing wrong with regards to any of the 1.10 changes. As I said, this compiled in 1.8.x and 1.9.x so just wanted to check that it wasn't some kind of unintended regression.
So I noticed that this only comes up in our buiilds for 32bit linux systems, which I plan on deprecating anyways (-m32 passed to ./Configure). Just passing this info along in case anyone else sees this issue.
What version of Go are you using (
go version
)?go version go1.10 linux/amd64
Does this issue reproduce with the latest release?
I am on latest release, but I have not tried the latest commit in master.
What operating system and processor architecture are you using (
go env
)?What did you do?
I have the following code which compiled in 1.8.x and 1.9.x:
What did you expect to see?
Proper compilation, switch is able to determine if interface is a
*C.size_t
or*C.ulong
.What did you see instead?
Longer output from
go build main.go -v -x
:The text was updated successfully, but these errors were encountered: