I want to refer to the field named type, but I get the following error because it is reserved in Go.
package main
/*
typedef struct {
int type;
} Struct;
*/
import "C"
import "fmt"
func main() {
test := C.Struct{1}
fmt.Println(test.type)
}
error
./Main.go:14:20: expected selector or type assertion, found 'type'
You can refer to it by adding an underscore to the field name when referencing.
package main
/*
typedef struct {
int type;
} Struct;
*/
import "C"
import "fmt"
func main() {
test := C.Struct{1}
fmt.Println(test._type) //Not type_See by type.
}
output
1
Recommended Posts