comparison libgo/misc/cgo/test/issue9557.go @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // cgo rewrote C.var to *_Cvar_var, but left
6 // C.var.field as _Cvar.var.field. It now rewrites
7 // the latter as (*_Cvar_var).field.
8 // See https://golang.org/issue/9557.
9
10 package cgotest
11
12 // struct issue9557_t {
13 // int a;
14 // } test9557bar = { 42 };
15 //
16 // struct issue9557_t *issue9557foo = &test9557bar;
17 import "C"
18 import "testing"
19
20 func test9557(t *testing.T) {
21 // implicitly dereference a Go variable
22 foo := C.issue9557foo
23 if v := foo.a; v != 42 {
24 t.Fatalf("foo.a expected 42, but got %d", v)
25 }
26
27 // explicitly dereference a C variable
28 if v := (*C.issue9557foo).a; v != 42 {
29 t.Fatalf("(*C.issue9557foo).a expected 42, but is %d", v)
30 }
31
32 // implicitly dereference a C variable
33 if v := C.issue9557foo.a; v != 42 {
34 t.Fatalf("C.issue9557foo.a expected 42, but is %d", v)
35 }
36 }