diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-02-28 17:18:03 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-02-28 17:18:03 +0700 |
commit | ee9b8fc921f48dc893808e1c9dbfbef321aa362c (patch) | |
tree | 0d0a5247b139ba68d2c2aa2d94e1d631476dbc62 /lang/zig/c-string.zig | |
parent | 2b91f9554b326aea138bd8a0acbfaa10d9ad59aa (diff) | |
download | cp-ee9b8fc921f48dc893808e1c9dbfbef321aa362c.tar.gz |
[lang/zig] Learn some Zig
Diffstat (limited to 'lang/zig/c-string.zig')
-rw-r--r-- | lang/zig/c-string.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lang/zig/c-string.zig b/lang/zig/c-string.zig new file mode 100644 index 0000000..537fa3b --- /dev/null +++ b/lang/zig/c-string.zig @@ -0,0 +1,12 @@ +const std = @import("std"); + +// This is also available as `std.c.printf`. +pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; + +pub fn main() anyerror!void { + _ = printf("Hello, world!\n"); // OK + + const msg = "Hello, world!\n"; + const non_null_terminated_msg: [msg.len]u8 = msg.*; + _ = printf(&non_null_terminated_msg); +} |