zig/test/standalone/mix_c_files/main.zig
mlugg f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00

31 lines
609 B
Zig

const std = @import("std");
extern fn add_C(x: i32) i32;
extern fn add_C_zig(x: i32) i32;
extern threadlocal var C_k: c_int;
export var zig_k: c_int = 1;
export fn add_zig(x: i32) i32 {
return x + zig_k + C_k;
}
export fn add_may_panic(x: i32) i32 {
if (x < 0) @panic("negative int");
return x + zig_k;
}
pub fn main() anyerror!void {
var x: i32 = 0;
x = add_zig(x);
x = add_C(x);
x = add_C_zig(x);
C_k = 200;
zig_k = 2;
x = add_zig(x);
x = add_C(x);
x = add_C_zig(x);
const u = @as(u32, @intCast(x));
try std.testing.expect(u / 100 == u % 100);
}