英文:
what is difference between *[] *types.a and [] *types.b in golang
问题
在上述代码中,函数声明如下:
func (c *Congress) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction, uncles []*types.Header, receipts *[]*types.Receipt, systemTxs []*types.Transaction) error {
其中,txs *[]*types.Transaction
和 uncles []*types.Header
是两个参数。在Go语言中,这两个参数的含义如下:
-
txs *[]*types.Transaction
:这是一个指向[]*types.Transaction
类型的指针。[]*types.Transaction
表示一个指向types.Transaction
类型的切片。因此,txs
是一个指向types.Transaction
类型切片的指针。 -
uncles []*types.Header
:这是一个[]*types.Header
类型的切片。[]*types.Header
表示一个指向types.Header
类型的切片。因此,uncles
是一个types.Header
类型切片。
希望以上解释对你理解Go语言中的术语有所帮助。
英文:
while looking into code I found below function declaration
func (c *Congress) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction, uncles []*types.Header, receipts *[]*types.Receipt, systemTxs []*types.Transaction) error {
where two parameters are txs *[]*types.Transaction, uncles []*types.Header,
what does it mean in terms of golang
just want to understand golang terminology with reference to above code
答案1
得分: 0
uncles []*types.Header
uncles是一个切片。如果你将它复制到其他地方(例如通过将其作为函数参数传递),对它的更新不会向原始切片传播(有一个细微差别,即对元素的更改会传播,但原始切片的大小/数据指针将保持不变)。
txs *[]*types.Transaction
txs是一个指向切片的指针。它有点像一个“引用”,因为对所指向的切片的更新会传播到指向该切片的其他地方。因此,如果将一个指向切片的指针作为函数参数传递,函数可能会更改所指向的切片的属性(添加/删除元素)。
英文:
uncles []*types.Header
uncles is slice. If you copy it somewhere (perhaps by passing it in as a function parameter) updates to it will not propagate backwards to the original (with the nuance that changes to elements will propagate, but the size/data pointer of the original will remain unchanged).
txs *[]*types.Transaction
txs is a pointer to a slice. It’s sort of like a “reference” in that updates to the slice pointed at propagate to anyone else pointing to that slice. So if you pass a pointer to a slice as a function parameter, the function may change the properties of the slice pointed to (adding/removing elements).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论