zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

sentinel-terminated_pointer.zig (374B) - Raw


      1 const std = @import("std");
      2 
      3 // This is also available as `std.c.printf`.
      4 pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
      5 
      6 pub fn main() anyerror!void {
      7     _ = printf("Hello, world!\n"); // OK
      8 
      9     const msg = "Hello, world!\n";
     10     const non_null_terminated_msg: [msg.len]u8 = msg.*;
     11     _ = printf(&non_null_terminated_msg);
     12 }
     13 
     14 // exe=build_fail
     15 // link_libc