PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

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