-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
broken packed struct initialization #21235
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
Comments
Here's a related example: const std = @import("std");
const S = packed struct {
a: usize = undefined,
b: usize,
};
pub fn main() void {
const s_const: S = .{ .b = 123 };
std.debug.print("{}\n", .{s_const.b});
var s_var: S = .{ .b = 123 };
_ = &s_var;
std.debug.print("{}\n", .{s_var.b});
} As of 0.14.0-dev.1349+6a21875dd, this prints
(at least for me; the second value will not necessarily be consistent since it appears to be uninitialized memory: https://godbolt.org/z/PM85achM7) This example works as expected (prints 123 twice) if any of the following changes are made:
May be related to #20095 and #20938 (both of which involve |
// var s_var: S = .{ .b = 123 };
var s_var: S = undefined;
s_var.b = 123; This does not change anything about the behaviour elsewhere, compared to the other workarounds |
Duplicate of #20938 |
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Expected Behavior
test passes
The text was updated successfully, but these errors were encountered: