Last active
December 24, 2020 22:27
-
-
Save jordanorelli/c1dd2e5fb0fcd0e3e5ea53514f93ad95 to your computer and use it in GitHub Desktop.
undefined values
This file contains hidden or 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"); | |
const stdout = std.io.getStdOut().writer(); | |
fn Box(comptime T: type) type { | |
return struct { | |
value: T, | |
}; | |
} | |
const Point = struct { | |
X: i32 = 1, | |
Y: i32 = 2, | |
}; | |
pub fn main() !void { | |
var vbox = Box(Point){ | |
.value = undefined, | |
}; | |
try stdout.print("var box with undefined: {}\n", vbox); | |
var vbox2 = Box(Point){ | |
.value = Point{}, | |
}; | |
try stdout.print("var box with explicit defaults: {}\n", vbox2); | |
const cbox = Box(Point){ | |
.value = undefined, | |
}; | |
try stdout.print("const box with undefined: {}\n", cbox); | |
try stdout.print("Box literal with undefined: {}\n", Box(Point){ | |
.value = undefined, | |
}); | |
} |
This file contains hidden or 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
var box with undefined: Point{ .X = -1431655766, .Y = -1431655766 } | |
var box with explicit defaults: Point{ .X = 1, .Y = 2 } | |
const box with undefined: Point{ .X = 0, .Y = 0 } | |
Box literal with undefined: Point{ .X = 0, .Y = 0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment