const.go
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// RUN: llgo -o %t %s
// RUN: %t 2>&1 | FileCheck %s
// CHECK: 0
// CHECK-NEXT: 1
// CHECK-NEXT: 1 1
// CHECK-NEXT: 1 1 1 4
// CHECK-NEXT: 2147483647
// CHECK-NEXT: -2147483648
// CHECK-NEXT: 2147483647
// CHECK-NEXT: -127
// CHECK-NEXT: false
// CHECK-NEXT: 10000000000
// CHECK-NEXT: 1
// CHECK-NEXT: 3
package main
import "runtime"
const (
a = iota * 2
A = 1
B
C
D = Z + iota
)
const (
Z = iota
Big = 1<<31 - 1
Big2 = -2147483648
Big3 = 2147483647
)
const (
expbits32 uint = 8
bias32 = -1<<(expbits32-1) + 1
darwinAMD64 = runtime.GOOS == "darwin" && runtime.GOARCH == "amd64"
)
func f1() float32 {
return 0
}
func constArrayLen() {
a := [...]int{1, 2, 3}
const x = len(a)
println(x)
}
func main() {
println(a)
println(B)
println(A, A)
println(A, B, C, D)
println(Big)
println(Big2)
println(Big3)
println(bias32)
// Currently fails, due to difference in C printf and Go's println
// formatting of the exponent.
//println(10 * 1e9)
println(darwinAMD64)
// Test conversion.
println(int64(10) * 1e9)
// Ensure consts work just as well when declared inside a function.
const (
x_ = iota
y_
)
println(y_)
constArrayLen()
}