package main
var a, b [0]int
var p, q = &a, &b
func main() {
if (p == q) {
p, q = &a, &b
println(p == q)
}
}
for true {...}
and for {...}
are not eqivalent
foo
shown below compiles, but bar
doesn't.
func foo() int {
for {}
}
func bar() int {
for true {}
}
make
built-in function to create a map, the second argument (cap
) can be negative
package main
var n = -100
func main() {
var m = make(map[int]bool, n)
m[123] = true;
}
cap
argument is equivalent to omitting it.
aConstantString[:]
is not a constant
package main
const s = "zigo 101" // len(s) == 8
var a byte = 1 << len(s) / 128
var b byte = 1 << len(s[:]) / 128
func main() {
println(a, b) // 2 0
}
0 0 2
.
package main
const N = 8
var n = N
func main() {
var x byte = 1 << n / 128
var y = byte(1 << n / 128)
var z byte = 1 << N / 128
println(x, y, z) // 0 0 2
}
1
are both assumed as byte
. So the two declarations are both eqivalent to the following line, in which the run-time expression byte(1) << n
overflows (and is truncated to 0).
... = byte(1) << n // 128
1 << N / 128
is evaluated at compile time. In the expression, 1
is treated as untyped int value.
var z = 2
The Go 101 project is hosted on Github. Welcome to improve Go 101 articles by submitting corrections for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies, description flaws, code bugs and broken links.
If you would like to learn some Go details and facts every serveral days, please follow Go 101's official Twitter account @zigo_101.