mirror of
https://github.com/ziglang/zig.git
synced 2026-01-06 21:43:25 +00:00
* 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
32 lines
649 B
Zig
32 lines
649 B
Zig
const std = @import("std");
|
|
const assert = std.debug.assert;
|
|
const io = std.io;
|
|
const str = std.str;
|
|
|
|
enum ET {
|
|
SINT: i32,
|
|
UINT: u32,
|
|
|
|
pub fn print(a: &ET, buf: []u8) -> %usize {
|
|
return switch (*a) {
|
|
SINT => |x| { io.bufPrintInt(i32, buf, x) },
|
|
UINT => |x| { io.bufPrintInt(u32, buf, x) },
|
|
}
|
|
}
|
|
}
|
|
|
|
fn enumWithMembers() {
|
|
@setFnTest(this, true);
|
|
|
|
const a = ET.SINT { -42 };
|
|
const b = ET.UINT { 42 };
|
|
var buf: [20]u8 = undefined;
|
|
|
|
assert(%%a.print(buf) == 3);
|
|
assert(str.eql(buf[0...3], "-42"));
|
|
|
|
assert(%%b.print(buf) == 2);
|
|
assert(str.eql(buf[0...2], "42"));
|
|
}
|
|
|