Created
April 18, 2021 00:23
-
-
Save marler8997/64338f902027783d2159abbaf796b6a6 to your computer and use it in GitHub Desktop.
Zig Copy Semantics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
test { | |
const U = union(enum) { | |
Val: isize, | |
Point: struct { x: isize, y: isize }, | |
}; | |
var u = U { .Point = .{ .x = 123, .y = 456 } }; | |
const p = &u.Point; | |
u = U { .Val = p.x + p.y }; | |
std.testing.expect(u.Val == 579); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment