1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import (
14 "fmt"
15 "os"
16 "timport/p"
17 )
18
19
20
21
22
23 var (
24 crossStruct = p.MakeHasSimdMethod()
25 crossIface = p.MakeSimdMethodIface()
26 )
27
28
29
30 func checkCrossPkgMethodDepVars() {
31 if crossStruct.X != 42 || crossIface == nil {
32 fmt.Printf("FAIL, unexpected cross-pkg values: X=%d iface=%v\n", crossStruct.X, crossIface)
33 os.Exit(1)
34 }
35 }
36
37
38
39
40 func checkSingleVarIdentity() {
41 fmt.Println("init:", p.N, p.GetN(), *p.PN)
42 if p.N < 16 || p.N&(p.N-1) != 0 {
43 fmt.Printf("FAIL, unexpected initial p.N = %d\n", p.N)
44 os.Exit(1)
45 }
46 if p.GetN() != p.N || *p.PN != p.N {
47 fmt.Printf("FAIL, init mismatch: p.N=%d p.GetN()=%d *p.PN=%d\n", p.N, p.GetN(), *p.PN)
48 os.Exit(1)
49 }
50 p.N = 1000
51 fmt.Println("after p.N=1000: p.N =", p.N, "p.GetN() =", p.GetN())
52 if p.N != 1000 || p.GetN() != 1000 {
53 fmt.Printf("FAIL, after p.N=1000: p.N=%d p.GetN()=%d\n", p.N, p.GetN())
54 os.Exit(1)
55 }
56 p.SetN(7)
57 fmt.Println("after p.SetN(7): p.N =", p.N, "p.GetN() =", p.GetN())
58 if p.N != 7 || p.GetN() != 7 {
59 fmt.Printf("FAIL, after p.SetN(7): p.N=%d p.GetN()=%d\n", p.N, p.GetN())
60 os.Exit(1)
61 }
62 fmt.Println("p.PN == &p.N:", p.PN == &p.N)
63 if p.PN != &p.N {
64 fmt.Println("FAIL, pointers are not equal")
65 os.Exit(1)
66 }
67 }
68
69 func main() {
70 checkCrossPkgMethodDepVars()
71 checkSingleVarIdentity()
72 }
73
View as plain text