Bools and bitfields

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Regarding the size of possible bitfields I would like to know why:
#include <stdbool.h>
struct s {
    bool f : 2;
};

fails to compile in gcc 4.3 and gcc 4.4 but not in gcc 4.2.

sizeof(bool) is 1, and C99 6.7.2.1 paragraph 3 seems to imply that the
bitfield size shouldn't be bigger than the width of the object.
"The expression that specifies the width of a bit-field shall be an
integer constant
expression with a nonnegative value that does not exceed the width of
an object of the
type that would be specified were the colon and expression omitted."

Therefore I would expect to have 1 to 8 as possible values for an 8
bit/byte architecture.


Cheers,
-- 
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux