-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
Currently, the bitCast builtin function works such that it "Asserts that @sizeOf(@TypeOf(value)) == @sizeOf(DestType)." I'm proposing that this is changed to be bitSizeOf to exclude padding bytes.
Why?
The main place I've found this interferes with programming is bit-casting to an integer which is a non-power of two in size. For example,
const Foo = packed struct {a: u8, b: u16}
const m_foo = Foo{.a = 5, .b = 73}
const as_int: u24 = @bitCast(u24, m_foo);
would not work because u24 is 4 bytes wide according to sizeOf, while Foo is 3 bytes wide, as is expected. Using bitSizeOf, this would compile, since both are 24 bits wide.
tecanec and McSinyx
Metadata
Metadata
Assignees
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.