change_active_union_field.zig (272B) - Raw
1 const std = @import("std"); 2 3 const Foo = union { 4 float: f32, 5 int: u32, 6 }; 7 8 pub fn main() void { 9 var f = Foo{ .int = 42 }; 10 bar(&f); 11 } 12 13 fn bar(f: *Foo) void { 14 f.* = Foo{ .float = 12.34 }; 15 std.debug.print("value: {}\n", .{f.float}); 16 } 17 18 // exe=succeed