This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Bools and bitfields
- From: "Paulo J. Matos" <pocmatos at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 11 Dec 2009 14:26:04 +0000
- Subject: 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