Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing structs by value #89

Closed
sporksmith opened this issue Dec 28, 2021 · 3 comments
Closed

Passing structs by value #89

sporksmith opened this issue Dec 28, 2021 · 3 comments

Comments

@sporksmith
Copy link

The idiomatic way to pass a struct that isn't modified is now to pass it by value: https://ziglang.org/documentation/master/#toc-Pass-by-value-Parameters

The text in 043_pointers5.zig directly contradicts this, and there are a lot of other places where pointer parameters probably ought to be changed to value parameters.

@ratfactor
Copy link
Owner

@sporksmith I keep meaning to say "thanks" for filing this issue. I agree that the example in ex 043 should be changed. At the very least, it should demonstrate pass-by-reference only when we are modifying the struct in the function. I'll check the other places where structs are passed. Thanks!

@sporksmith
Copy link
Author

You're quite welcome! I originally was mulling over sending a PR but wasn't really sure the best way to introduce the idea, so figured I'd at least raise the issue.

@ratfactor
Copy link
Owner

Six months later: The above commit should do the trick. I changed Exercise 043 to use a "linked" struct so the pass by reference makes more sense. Corrected a few other minor instances in other exercises. Interestingly, most later exercises used the correct idiom. Thanks again for submitting this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants