In the code below:
const (
signature uint32 = 0xae3179fb
dhkxGroup = 2
ReplySuccessful byte = iota
ReplyBufferCorrupted
ReplyDecryptFailed
ReplySessionExpired
ReplyPending
)
ReplySuccessful is compiled to 2, while I think it should definitly be ZERO. If I move signature and dhkxGroup below ReplyPending, then ReplySuccessful becomes 0.
Why is this?
PS. To me, the only "benefit" of using iota is that you can ommit the value assigned to later constants, so that you can easily modify/insert new values. However, if iota is not FIXED to zero, it could cause big problem especially in doing things like communication protocols.
The spec defines iota's usage in Go (emphasis added):
Note that the index is relative to the
ConstSpec, basically meanining the currentconstblock.Of particular interest is probably the example provided:
Notice line 3 (iota value 2) is unused. You have essentially the same, with two unused values coming first.
What you probably meant in your code is:
See it on the playground