zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3b501b2d81e26fcadd15495eac62545fab1c4b49 (tree)
parent 497329622ae49908da6bb61faee1b39f3ade0b96
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date:   Thu,  6 Oct 2022 00:54:45 -0400

c: cast NULL in advance to avoid comparison warnings

Diffstat:
Msrc/codegen/c.zig | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/codegen/c.zig b/src/codegen/c.zig @@ -655,11 +655,11 @@ pub const DeclGen = struct { return dg.fail("TODO: C backend: implement lowering large float values", .{}); }, .Pointer => switch (val.tag()) { - .null_value => try writer.writeAll("NULL"), - // Technically this should produce NULL but the integer literal 0 will always coerce - // to the assigned pointer type. Note this is just a hack to fix warnings from ordered comparisons (<, >, etc) - // between pointers and 0, which is an extension to begin with. - .zero => try writer.writeByte('0'), + .null_value, .zero => { + try writer.writeAll("(("); + try dg.renderTypecast(writer, ty); + try writer.writeAll(")NULL)"); + }, .variable => { const decl = val.castTag(.variable).?.data.owner_decl; return dg.renderDeclValue(writer, ty, val, decl);