mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-08-08 16:21:43 +00:00
ch3: fix code path
This commit is contained in:
@@ -36,9 +36,8 @@ const (
|
||||
|
||||
隨着iota的遞增,每個常量對應表達式1 << iota,是連續的2的冪,分别對應一個bit位置。使用這些常量可以用於測試、設置或清除對應的bit位的值:
|
||||
|
||||
<u><i>gopl.io/ch3/netflag</i></u>
|
||||
```Go
|
||||
gopl.io/ch3/netflag
|
||||
|
||||
func IsUp(v Flags) bool { return v&FlagUp == FlagUp }
|
||||
func TurnDown(v *Flags) { *v &^= FlagUp }
|
||||
func SetBroadcast(v *Flags) { *v |= FlagBroadcast }
|
||||
@@ -74,5 +73,3 @@ const (
|
||||
不過iota常量生成規則也有其局限性。例如,它併不能用於産生1000的冪(KB、MB等),因爲Go語言併沒有計算冪的運算符。
|
||||
|
||||
**練習 3.13:** 編寫KB、MB的常量聲明,然後擴展到YB。
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user