2016-09-15 11:07:35 -07:00
|
|
|
var argv: &&const u8 = undefined;
|
|
|
|
|
|
|
|
fn constSliceChild() {
|
2016-12-25 15:31:57 -08:00
|
|
|
@setFnTest(this);
|
2016-09-27 23:33:32 -07:00
|
|
|
|
2016-09-15 11:07:35 -07:00
|
|
|
const strs = ([]&const u8) {
|
|
|
|
c"one",
|
|
|
|
c"two",
|
|
|
|
c"three",
|
|
|
|
};
|
|
|
|
argv = &strs[0];
|
|
|
|
bar(strs.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo(args: [][]const u8) {
|
|
|
|
assert(args.len == 3);
|
|
|
|
assert(streql(args[0], "one"));
|
|
|
|
assert(streql(args[1], "two"));
|
|
|
|
assert(streql(args[2], "three"));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar(argc: usize) {
|
2016-12-25 15:31:57 -08:00
|
|
|
const args = @alloca([]u8, argc);
|
2016-09-15 11:07:35 -07:00
|
|
|
for (args) |_, i| {
|
|
|
|
const ptr = argv[i];
|
|
|
|
args[i] = ptr[0...strlen(ptr)];
|
|
|
|
}
|
|
|
|
foo(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn strlen(ptr: &const u8) -> usize {
|
|
|
|
var count: usize = 0;
|
|
|
|
while (ptr[count] != 0; count += 1) {}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn streql(a: []const u8, b: []const u8) -> bool {
|
|
|
|
if (a.len != b.len) return false;
|
|
|
|
for (a) |item, index| {
|
|
|
|
if (b[index] != item) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-25 15:31:57 -08:00
|
|
|
|
|
|
|
// TODO const assert = @import("std").debug.assert;
|
|
|
|
fn assert(ok: bool) {
|
|
|
|
if (!ok)
|
|
|
|
@unreachable();
|
|
|
|
}
|