aboutsummaryrefslogtreecommitdiff
path: root/doc/langref/change_active_union_field.zig
blob: 6170dae69decddd6161ad9c0ead9889aa8727a17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.* = Foo{ .float = 12.34 };
    std.debug.print("value: {}\n", .{f.float});
}

// exe=succeed