-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Pointer to Tagged Union is being silently overwritten #6357
Comments
The issue is with lifetimes of temporaries. In particular, the capture of the ranged for loop you're using, When passing things by immutable value (in captures as well as function arguments), Zig reserves the right to freely decide whether to implement this by copying them or pointing to them in-place. ... Sorry if I got carried away; use a pointer capture for this, |
Of course! I'm generating temporary copies in the loop. |
In the following code example I am conditionally assigning a pointer to an tagged union in a loop.
The print statement next to the pointer assignment fires only once and with the correct entry in the array.
However somehow it seems to be getting silently assigned with each iteration of the loop and in the end will always unconditionally point to the last element in the array.
The code example is stripped down from my first program written in zig, so apologies if I am making some basic mistake here.
This is using the latest windows build: zig-windows-x86_64-0.6.0+d07383689
The text was updated successfully, but these errors were encountered: