Is working past the end of a slice idiomatic?

前端 未结 2 656
执笔经年
执笔经年 2021-01-22 16:10

I was reading through Go\'s compress/flate package, and I found this odd piece of code [1]:

n := int32(len(list))
list = list[0 : n+1]
list[n] = max         


        
2条回答
  •  误落风尘
    2021-01-22 16:46

    It cannot be a run time exception because the language specification prescribes that the upper limit of the slice operation is the capacity of the slice, not its length.

提交回复
热议问题