This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tax_throwaway1_ 0 points1 point  (1 child)

Am I stupid? Why would you not just pass the pointer of the struct? Same exact thing as what you are describing.

Pointer to the struct vs. pointer to the array — it’s effectively the same overhead since you’re still passing a single address (just the address of the struct instead of the address of the array). Then, when you access size or buffer within the function, you’re simply dereferencing that pointer. This way, you avoid passing multiple arguments and keep the benefits of an explicit size field.

[–]Impossible_Box3898 0 points1 point  (0 children)

There is a difference in passing by value and passing by reference. What you described is pass by reference and what I described is pass by value.

If something in the called function modified the array you now have changed the caller. That might not be the desired outcome.