I am reading the code about go runtime. In chan.go, I can't understand this.
const (
maxAlign = 8
hchanSize = unsafe.Sizeof(hchan{}) + uintptr(-int(unsafe.Sizeof(hchan{}))&(maxAlign-1))
)
what is the "-" behand the "uintptr" means? Thanks.
The "-" is the minus sign. It performs the unary negation of the size of the hchanSize structure. The whole expression is doing a bit of bit manipulation to round the size up to the next larger multiple of 8.
I'm not sure why you want to know this but if you understand bits operations like & and 2's-complement arithmetic you can work through it with different values. Eg try using 9 in place of unsafe.Sizeof(hchan) and see that it rounds up to 16.