| author | |
| committer | |
| log | 5de07ab721380c39130a0bd3277a272673e3d644 |
| tree | ff3ae571b56ac02df30d4ffcc60df4b6848361fc |
| parent | db0a5e7516fa8cf733fc11d493cadea1efbe5f27 |
2 files changed, 11 insertions(+), 4 deletions(-)
example/hello_world/hello.zig+6-2| ... | ... | @@ -1,5 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn main() void { | |
| 4 | std.debug.warn("Hello, world!\n"); | |
| 3 | pub fn main() !void { | |
| 4 | // If this program is run without stdout attached, exit with an error. | |
| 5 | const stdout_file = try std.io.getStdOut(); | |
| 6 | // If this program encounters pipe failure when printing to stdout, exit | |
| 7 | // with an error. | |
| 8 | try stdout_file.write("Hello, world!\n"); | |
| 5 | 9 | } |
example/hello_world/hello_libc.zig+5-2| ... | ... | @@ -2,9 +2,12 @@ const c = @cImport({ |
| 2 | 2 | // See https://github.com/ziglang/zig/issues/515 |
| 3 | 3 | @cDefine("_NO_CRT_STDIO_INLINE", "1"); |
| 4 | 4 | @cInclude("stdio.h"); |
| 5 | @cInclude("string.h"); | |
| 5 | 6 | }); |
| 6 | 7 | |
| 7 | export fn main(argc: c_int, argv: [*]?[*]u8) c_int { | |
| 8 | _ = c.fprintf(c.stderr, c"Hello, world!\n"); | |
| 8 | const msg = c"Hello, world!\n"; | |
| 9 | ||
| 10 | export fn main(argc: c_int, argv: **u8) c_int { | |
| 11 | if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1; | |
| 9 | 12 | return 0; |
| 10 | 13 | } |