Created
January 20, 2023 21:22
-
-
Save Reijaff/f622d0d4da686391003ee6a24ed2e2f5 to your computer and use it in GitHub Desktop.
convert string to stack string at compile time in zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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