C bitfields guarantees

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sun Jul 7 02:43:47 UTC 2024


On 07/07/2024 2:22 PM, cc wrote:
> On Friday, 5 July 2024 at 05:37:50 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> Today many people have spent some time to try and understand Walter's 
>> belief that C is "good enough" for bit fields in terms of guarantees.
> 
> Can I define my D struct using bitfields, and then correctly unpack them 
> in a GLSL shader using bitfieldExtract() with the predicted offsets and 
> sizes?  If the answer is no, then that bitfield implementation belongs 
> in a garbage can.
> 
> Currently the answer to this question is "yes" for std.bitmanip and "no" 
> for "native" D bitfields.

Yes and no.

If it is exactly 32bits, its fine.

If it unintentionally crosses above it (due to implementation defined 
behavior), or if it is (u)int 2/3/4 then it likely won't work.


More information about the Digitalmars-d mailing list