1 回答

TA貢獻1921條經(jīng)驗 獲得超9個贊
該規(guī)范定義了iota在Go中的用法(著重號是后加的):
在常量聲明中,預(yù)聲明的標識符 iota 表示連續(xù)的非類型化整數(shù)常量。它的值是該常量聲明中相應(yīng) ConstSpec 的索引,從零開始。
請注意,索引是相對于 的,基本上表示當前塊。ConstSpec
const
特別令人感興趣的可能是提供的示例:
const (
a = 1 << iota // a == 1 (iota == 0)
b = 1 << iota // b == 2 (iota == 1)
c = 3 // c == 3 (iota == 2, unused)
d = 1 << iota // d == 8 (iota == 3)
)
請注意,第 3 行(值 2)未使用。您基本上具有相同的,首先是兩個未使用的值。
您在代碼中可能意味著:
const (
signature uint32 = 0xae3179fb
dhkxGroup = 2
)
const (
ReplySuccessful byte = iota
ReplyBufferCorrupted
ReplyDecryptFailed
ReplySessionExpired
ReplyPending
)
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報