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
What version of Go are you using (go version)?
go version go1.4 linux/amd64
Issue
The specification states that "if the type of x is a named pointer type and (*x).f is a valid selector expression denoting a field (but not a method), x.f is shorthand for (*x).f."
When a C variable containing a struct pointer is assigned to a Go variable, the shorthand applies to selector expressions using that variable. However, it seems that the shorthand does not apply in the case that the C variable is named directly, without the use of a temporary variable. I try to illustrate this in the example below:
package main
import (
"fmt"
)
// struct blah {
// int a;
// };
//
// struct blah *foo;
//
// void
// blah_alloc() {
// foo = malloc(sizeof(struct blah));
// foo->a = 7;
// }
import "C"
type bar struct {
a int
}
var buzz *bar
func init() {
buzz = &bar{}
}
func main() {
// works
// implicit foo.a -> (*foo).a
foo := C.foo
fmt.Println(foo.a)
// works
fmt.Println((*C.foo).a)
// doesn't work, compiler displays an error
// implicit C.foo -> (*C.foo).a
fmt.Println(C.foo.a)
// works
fmt.Println(buzz.a)
}
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
Selector pointer shorthand does not operate with cgo structs named directly
spec: Selector pointer shorthand does not operate with cgo structs named directly
Jan 10, 2015
mikioh
changed the title
spec: Selector pointer shorthand does not operate with cgo structs named directly
cmd/cgo: Selector pointer shorthand does not operate with cgo structs named directly
Jan 10, 2015
What version of Go are you using (go version)?
go version go1.4 linux/amd64
Issue
The specification states that "if the type of x is a named pointer type and (*x).f is a valid selector expression denoting a field (but not a method), x.f is shorthand for (*x).f."
When a C variable containing a struct pointer is assigned to a Go variable, the shorthand applies to selector expressions using that variable. However, it seems that the shorthand does not apply in the case that the C variable is named directly, without the use of a temporary variable. I try to illustrate this in the example below:
The text was updated successfully, but these errors were encountered: