This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bools and bitfields


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]