Skip to content

Instantly share code, notes, and snippets.

@Reijaff
Created January 20, 2023 21:22
Show Gist options
  • Save Reijaff/f622d0d4da686391003ee6a24ed2e2f5 to your computer and use it in GitHub Desktop.
Save Reijaff/f622d0d4da686391003ee6a24ed2e2f5 to your computer and use it in GitHub Desktop.
convert string to stack string at compile time in zig
const std = @import("std");
fn stack_string(comptime string: []const u8) [string.len]u8{
var new_string: [string.len]u8 = undefined;
inline for (string) |chr, idx|{
new_string[idx] = chr;
}
return new_string;
}
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("{s}\n", .{stack_string("hello my dear friend")});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment