1 // $G $D/$F.go && $L $F.$A && ./$A.out
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
19 var x = []int{1, 2, 3}
21 func f(x int, len *byte) {
25 func whatis(x interface{}) string {
26 switch xx := x.(type) {
28 return fmt.Sprint("default ", xx)
29 case int, int8, int16, int32:
30 return fmt.Sprint("signed ", xx)
32 return fmt.Sprint("signed64 ", int64(xx))
33 case uint, uint8, uint16, uint32:
34 return fmt.Sprint("unsigned ", xx)
36 return fmt.Sprint("unsigned64 ", uint64(xx))
38 return fmt.Sprint("nil ", xx)
43 func whatis1(x interface{}) string {
47 return fmt.Sprint("default ", xx)
48 case int, int8, int16, int32:
49 return fmt.Sprint("signed ", xx)
51 return fmt.Sprint("signed64 ", xx.(int64))
52 case uint, uint8, uint16, uint32:
53 return fmt.Sprint("unsigned ", xx)
55 return fmt.Sprint("unsigned64 ", xx.(uint64))
57 return fmt.Sprint("nil ", xx)
62 func check(x interface{}, s string) {
65 fmt.Println("whatis", x, "=>", w, "!=", s)
71 fmt.Println("whatis1", x, "=>", w, "!=", s)
78 check(uint(1), "unsigned 1")
79 check(int64(1), "signed64 1")
80 check(uint64(1), "unsigned64 1")
81 check(1.5, "default 1.5")
82 check(nil, "nil <nil>")