PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Examples/go/pointer/runme.go

#
Go | 47 lines | 29 code | 10 blank | 8 comment | 0 complexity | 8e36a29746fe17dde0979fcad41d5961 MD5 | raw file
 1package main
 2
 3import (
 4	"fmt"
 5	. "./example"
 6)
 7
 8func main() {
 9	// First create some objects using the pointer library.
10	fmt.Println("Testing the pointer library")
11	a := New_intp()
12	b := New_intp()
13	c := New_intp()
14	Intp_assign(a, 37)
15	Intp_assign(b, 42)
16
17	fmt.Println("     a =", a)
18	fmt.Println("     b =", b)
19	fmt.Println("     c =", c)
20
21	// Call the add() function with some pointers
22	Add(a, b, c)
23
24	// Now get the result
25	res := Intp_value(c)
26	fmt.Println("     37 + 42 =", res)
27
28	// Clean up the pointers
29	Delete_intp(a)
30	Delete_intp(b)
31	Delete_intp(c)
32
33	// Now try the typemap library
34	// Now it is no longer necessary to manufacture pointers.
35	// Instead we use a single element slice which in Go is modifiable.
36
37	fmt.Println("Trying the typemap library")
38	r := []int{0}
39	Sub(37, 42, r)
40	fmt.Println("     37 - 42 = ", r[0])
41
42	// Now try the version with return value
43
44	fmt.Println("Testing return value")
45	q := Divide(42, 37, r)
46	fmt.Println("     42/37 = ", q, " remainder ", r[0])
47}