zig/test/cases/var_args.zig

28 lines
523 B
Zig
Raw Normal View History

const assert = @import("std").debug.assert;
fn add(args: ...) -> i32 {
var sum = i32(0);
{comptime var i: usize = 0; inline while (i < args.len; i += 1) {
sum += args[i];
}}
return sum;
}
fn testAddArbitraryArgs() {
@setFnTest(this);
assert(add(i32(1), i32(2), i32(3), i32(4)) == 10);
assert(add(i32(1234)) == 1234);
assert(add() == 0);
}
fn readFirstVarArg(args: ...) {
const value = args[0];
}
fn sendVoidArgToVarArgs() {
@setFnTest(this);
readFirstVarArg({});
}