You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the program prints (0, 1), which was my intention when I wrote the above Zig code.
I'm fairly new to Zig, but the behavior in C feels much more intuitive. I would expect the struct initializer to be fully evaluated before any data is written into p.
The text was updated successfully, but these errors were encountered:
aidanbabo
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Dec 6, 2024
In essence, Zig desugars the assignment foo = .{ .a = x, .b = y } to the two statements foo.a = x; foo.b = y; .
In your example code, p = .{ .r = p.c, .c = -p.r }; becomes p.r = p.c; p.c = -p.r;.
The workaround for now is to specify the type (p = Point{ .r = p.c, .c = -p.r };), or use a temporary const new_p = ...; p = new_p;.
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Sorry for the lengthy title. Given a snippet of Zig code like below:
the program prints
(0, 0)
when run.The struct and function are marked as export because I was working with them in Godbolt, but the problem manifest with Zig's layout/cc as well.
Expected Behavior
Given a similar snipped of C code:
the program prints
(0, 1)
, which was my intention when I wrote the above Zig code.I'm fairly new to Zig, but the behavior in C feels much more intuitive. I would expect the struct initializer to be fully evaluated before any data is written into
p
.The text was updated successfully, but these errors were encountered: