Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Last active December 24, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanorelli/c1dd2e5fb0fcd0e3e5ea53514f93ad95 to your computer and use it in GitHub Desktop.
Save jordanorelli/c1dd2e5fb0fcd0e3e5ea53514f93ad95 to your computer and use it in GitHub Desktop.
undefined values
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,
});
}
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