3 ms·
There are two separate problems that'd need solving to handle bitfields: 1) Having uN and possibly iN types, for general-purpose use. 2) Placing such types at
by JoshTriplett 6y ago
There are two separate problems that'd need solving to handle bitfields:
1) Having uN and possibly iN types, for general-purpose use.
2) Placing such types at specific offsets within a struct.
C only handles the second of those: you can have an N-bit type, but when you extract it it comes out as the wider type you constrain it from. So, `unsigned field:5;` will get read as an `unsigned`, not a `u5`.
Rust could handle both, if appropriate sized types exist. (Const generics might be nice here, to parameterize on the type width.) (1) alone won't solve the problem, without some way to define how those types are packed into the struct.