Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

usizeCastForWrappingPtrArithmetic

Cast a signed integer node to a usize, for use in pointer arithmetic. Negative numbers will become very large positive numbers but that is ok since we only use this in pointer arithmetic expressions, where wraparound will ensure we get the correct value. node -> @as(usize, @bitCast(@as(isize, @intCast(node))))

Translator.usizeCastForWrappingPtrArithmetic
fn usizeCastForWrappingPtrArithmetic(t: *Translator, node: ZigNode) TransError!ZigNode

File

lib/compiler/translate-c/Translator.zig:4153

Code

fn usizeCastForWrappingPtrArithmetic(t: *Translator, node: ZigNode) TransError!ZigNode {
    const intcast_node = try ZigTag.as.create(t.arena, .{
        .lhs = try ZigTag.type.create(t.arena, "isize"),
        .rhs = try ZigTag.int_cast.create(t.arena, node),
    });

    return ZigTag.as.create(t.arena, .{
        .lhs = try ZigTag.type.create(t.arena, "usize"),
        .rhs = try ZigTag.bit_cast.create(t.arena, intcast_node),
    });
}