bit-fields

Jun 3, 2014 at 6:48am
Can bit-fields only be fields of a structure/union, never “normal”, “stand-alone” variables?
Jun 3, 2014 at 7:32am
Yes, that's right.
Jun 3, 2014 at 12:43pm
but why it is so...?
Jun 3, 2014 at 12:44pm
n with bit-fields we can only use char and int?
Jun 3, 2014 at 2:49pm
The type of a bit field can be any integral (that's bool, char, int, etc) or enum type. http://en.cppreference.com/w/cpp/language/bit_field
Jun 12, 2014 at 12:08pm
thanks cubbi for reply.

but in your reference link also bit field use with structure.

why we can not use it “stand-alone”?
Jun 12, 2014 at 1:40pm
What would that accomplish?

A bit field that is not part of a struct would presumably occupy a full word so why not just use an integral type?

By forcing bit fields to be members of a struct, it becomes clear how the bits are packed.

Topic archived. No new replies allowed.