1

I have this code:

const std = @import("std");
const print = std.debug.print;
pub fn main() void {
    var n: u8 = 1;
    print("{s}\n", .{if (n == 0) "0" else "1"});
}

But it does not do what I want. The output is "0".

Could anyone tell me what happend? Thanks a lot.

4

1 回答 1

0

Zig is not yet stable and in special stage1 (the current bootstrapping compiler) will not be, as the intention is to delete it and replace the bootstrapping compiler with generated c code one from stage2 (as the new bootstrapping compiler).

In contrast to that will stage2 (currently in development) handle these things properly.

This is a known miscompilation.

Please first search upstream, under https://github.com/ziglang/zig/issues with labels stage1 and miscompilation.

于 2021-12-25T15:20:39.537 回答