about summary refs log tree commit diff
path: root/lang/zig/c-string.zig
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-02-28 17:18:03 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-02-28 17:18:03 +0700
commitee9b8fc921f48dc893808e1c9dbfbef321aa362c (patch)
tree0d0a5247b139ba68d2c2aa2d94e1d631476dbc62 /lang/zig/c-string.zig
parent2b91f9554b326aea138bd8a0acbfaa10d9ad59aa (diff)
downloadcp-ee9b8fc921f48dc893808e1c9dbfbef321aa362c.tar.gz
[lang/zig] Learn some Zig
Diffstat (limited to 'lang/zig/c-string.zig')
-rw-r--r--lang/zig/c-string.zig12
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);
+}