Commit 4bf149795a

Andrew Kelley <superjoe30@gmail.com>
2017-10-01 18:40:30
update hello world examples
edge cases matter See #510
1 parent a2e6ada
Changed files (2)
example
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");
 }
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;
 }