You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
934 B
Zig

4 years ago
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){
4 years ago
.value = undefined, // this is gonna be junk
4 years ago
};
try stdout.print("var box with undefined: {}\n", vbox);
var vbox2 = Box(Point){
4 years ago
.value = Point{}, // this is the default value
4 years ago
};
try stdout.print("var box with explicit defaults: {}\n", vbox2);
4 years ago
// looks like the value of this winds up in bss.
// https://en.wikipedia.org/wiki/.bss
4 years ago
const cbox = Box(Point){
4 years ago
.value = undefined, // this is zeroed out memory
4 years ago
};
try stdout.print("const box with undefined: {}\n", cbox);
try stdout.print("Box literal with undefined: {}\n", Box(Point){
4 years ago
.value = undefined, // this is also zeroed out memory
4 years ago
});
}