zig/test/cases/var_params.zig
Andrew Kelley b581da41f8 remove compiler directives
* add `setFnTest`, `setFnVisible`, `setFnStaticEval`,
   `setFnNoInline` builtin functions to replace previous
   directive functionality
 * add `coldcc` and `nakedcc` as keywords which can be used as part
   of a function prototype.
 * `setDebugSafety` builtin can be used to set debug safety features
   at a per block scope level.
 * closes #169
2016-09-28 02:33:32 -04:00

36 lines
618 B
Zig

const assert = @import("std").debug.assert;
fn varParams() {
@setFnTest(this, true);
assert(max_i32(12, 34) == 34);
assert(max_f64(1.2, 3.4) == 3.4);
assert(max_i32_noeval(12, 34) == 34);
assert(max_f64_noeval(1.2, 3.4) == 3.4);
}
fn max(a: var, b: var) -> @typeOf(a) {
if (a > b) a else b
}
fn max_i32(a: i32, b: i32) -> i32 {
max(a, b)
}
fn max_f64(a: f64, b: f64) -> f64 {
max(a, b)
}
fn max_i32_noeval(a: i32, b: i32) -> i32 {
@setFnStaticEval(this, false);
max(a, b)
}
fn max_f64_noeval(a: f64, b: f64) -> f64 {
@setFnStaticEval(this, false);
max(a, b)
}