Created
April 19, 2019 10:55
-
-
Save ljmccarthy/248b3b269583e31f6e00adda44eac43e to your computer and use it in GitHub Desktop.
This file contains 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
fn cString(comptime str: []const u8) [*]const u8 { | |
return &(str ++ "\x00"); | |
} | |
fn cStringArray(comptime strArray: [][]const u8) [*]const ?[*]const u8 { | |
comptime var out : [strArray.len + 1] ?[*]const u8 = undefined; | |
inline for (strArray) |str, i| { | |
out[i] = comptime cString(str); | |
} | |
out[strArray.len] = null; | |
return &out; | |
} | |
test "null terminated array of null terminated strings" { | |
var argv = cStringArray(&[][]const u8{ | |
"hello", | |
"world", | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment