Are there any downsides to passing structs by value in C, rather than passing a pointer?

前端 未结 10 2163
野的像风
野的像风 2020-11-28 01:26

Are there any downsides to passing structs by value in C, rather than passing a pointer?

If the struct is large, there is obviously the performancd aspect of copying

10条回答
  •  渐次进展
    2020-11-28 01:57

    I think that your question has summed things up pretty well.

    One other advantage of passing structs by value is that memory ownership is explicit. There is no wondering about if the struct is from the heap, and who has the responsibility for freeing it.

提交回复
热议问题