Actually, for bitfields the types into which the bits are packed are not
left to the compiler. If you said "int c : 4", then it will use a "int".

If you have:

int a : 24;
int b : 24;
int c : 16;

and int is 32 bits on your platform, then a will be 24 somewhere in 32
bits, same thing for b, and c will be 16 bits somewhere in 32 bits; for a
single bit field cannot be split among several underlying integers.

Exactly where the bits lie within the type, though, is part of the ABI.

-- Matthieu


On Sun, Sep 8, 2013 at 4:31 PM, Corey Richardson <[email protected]> wrote:

> On Sun, Sep 8, 2013 at 3:00 AM, Martin DeMello <[email protected]>wrote:
>
>> I was looking at the bindgen bug for incorrect bitfield handling
>>
>> https://github.com/crabtw/rust-bindgen/issues/8
>>
>> but from a quick pass through the rust manual I can't figure out what
>> the correct behaviour would be.
>>
>> What, for example, would the correct bindgen output for the following be:
>>
>> struct bit {
>>   int alpha : 12;
>>   int beta : 6;
>>   int gamma : 2;
>> };
>>
>>
> You'll have to check what the various C compilers do with bitfields. I
> imagine they pack the bitfields into the smallest integer type that will
> contain them all. But, almost everything about bitfields is entirely
> implementation defined, so it's probably going to be difficult to come up
> with what to do correctly in any portable way.
>
> Once you actually figure out what to generate, though, methods for
> getting/setting the bitfields would probably be best.
>
>
>
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to