zig/doc/langref/runtime_wrong_union_field_access.zig

19 lines
257 B
Zig
Raw Permalink Normal View History

const std = @import("std");
const Foo = union {
float: f32,
int: u32,
};
pub fn main() void {
var f = Foo{ .int = 42 };
bar(&f);
}
fn bar(f: *Foo) void {
f.float = 12.34;
std.debug.print("value: {}\n", .{f.float});
}
// exe=fail