DoxigAlpha

Function parameters

Parameters

#
DestType:type
target:anytype

Type definitions in this namespace

Types

#

Given a type and value, cast the value to the type as c would.

Functions

#
cast
Given a type and value, cast the value to the type as c would.
sizeof
Given a value returns its size as C's sizeof operator would.
promoteIntLiteral
Promote the type of an integer literal until it fits as C would.
shuffleVectorIndex
Convert from clang __builtin_shufflevector index to Zig @shuffle index
FlexibleArrayType
Constructs a [*c] pointer with the const and volatile annotations
signedRemainder
C `%` operator for signed integers

Source

Implementation

#
fn castInt(comptime DestType: type, target: anytype) DestType {
    const dest = @typeInfo(DestType).int;
    const source = @typeInfo(@TypeOf(target)).int;

    if (dest.bits < source.bits)
        return @as(DestType, @bitCast(@as(std.meta.Int(source.signedness, dest.bits), @truncate(target))))
    else
        return @as(DestType, @bitCast(@as(std.meta.Int(source.signedness, dest.bits), target)));
}