about summary refs log tree commit diff
path: root/lang/zig/c-string.zig
diff options
context:
space:
mode:
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);
+}