-
Notifications
You must be signed in to change notification settings - Fork 486
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
Comments
@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! |
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. |
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! |
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.The text was updated successfully, but these errors were encountered: