variable initializations are now mandatory

use `undefined` if you want uninitialized memory
This commit is contained in:
Andrew Kelley
2016-01-25 23:56:46 -07:00
parent b215a3e0b6
commit 4e43973413
8 changed files with 29 additions and 32 deletions

View File

@@ -18,11 +18,10 @@ pub fn main(args: [][]u8) -> %void {
} else if (arg[0] == '-') {
return usage(exe);
} else {
var is: InputStream;
is.open(arg, OpenReadOnly) %% |err| {
var is = input_stream_open(arg, OpenReadOnly) %% |err| {
%%stderr.print("Unable to open file: {}", ([]u8)(err));
return err;
}
};
defer is.close();
catted_anything = true;
@@ -40,7 +39,7 @@ fn usage(exe: []u8) -> %void {
}
fn cat_stream(is: InputStream) -> %void {
var buf: [1024 * 4]u8;
var buf: [1024 * 4]u8 = undefined;
while (true) {
const bytes_read = is.read(buf) %% |err| {

View File

@@ -6,7 +6,7 @@ import "rand.zig";
pub fn main(args: [][]u8) -> %void {
%%stderr.print_str("Welcome to the Guess Number Game in Zig.\n");
var seed : u32;
var seed : u32 = undefined;
const seed_bytes = (&u8)(&seed)[0...4];
%%os_get_random_bytes(seed_bytes);
@@ -16,7 +16,7 @@ pub fn main(args: [][]u8) -> %void {
while (true) {
%%stderr.print_str("\nGuess a number between 1 and 100: ");
var line_buf : [20]u8;
var line_buf : [20]u8 = undefined;
const line_len = stdin.read(line_buf) %% |err| {
%%stderr.print_str("Unable to read from stdin.\n");