From 4bf149795acea088b349be89cb7992a6d413ad9f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 1 Oct 2017 12:40:30 -0400 Subject: [PATCH] update hello world examples edge cases matter See #510 --- example/hello_world/hello.zig | 2 +- example/hello_world/hello_libc.zig | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/example/hello_world/hello.zig b/example/hello_world/hello.zig index 03eab6ac56..d723ad284c 100644 --- a/example/hello_world/hello.zig +++ b/example/hello_world/hello.zig @@ -1,5 +1,5 @@ const io = @import("std").io; pub fn main() -> %void { - %%io.stdout.printf("Hello, world!\n"); + %return io.stdout.printf("Hello, world!\n"); } diff --git a/example/hello_world/hello_libc.zig b/example/hello_world/hello_libc.zig index ea8a9df38e..22c0ee784d 100644 --- a/example/hello_world/hello_libc.zig +++ b/example/hello_world/hello_libc.zig @@ -1,6 +1,13 @@ -const c = @cImport(@cInclude("stdio.h")); +const c = @cImport({ + @cInclude("stdio.h"); + @cInclude("string.h"); +}); + +const msg = c"Hello, world!\n"; export fn main(argc: c_int, argv: &&u8) -> c_int { - _ = c.printf(c"Hello, world!\n"); + if (c.printf(msg) != c_int(c.strlen(msg))) + return -1; + return 0; }