If you have a positive number on a signed int.
const i: i32 = 123;
~i will be negative.
assert(~i < 0)
this could be solved with a @bitCast() since @intCast() does not allow to change the sign.
const u: u32 = @bitCast(~i)
2nd problem: c_ulong and c_int have different bitsized
@bitCast only works if they have the same size.
Solution 1:
First use @intCast() and then use ~
that you don't cast a negative number.
Solution 2: Use a @bitCast() to change the type from c_int to c_uint. and then use @intCast() from c_uint to c_ulong.