[...]
gcc, for one, seems to give _Bool CHAR_BIT value bits. The effect is
that, given an object b of type_Bool, the expressions b and (_Bool)b
need not have the same value. Is _Bool the only type with this
property?
As of gcc 4.3.3, sizeof (_Bool) is 1, but it appears that only one of
the 8 bits is a value bit.
If I try to declare a bool bit field wider than one bit, I get:
error: width of 'b2' exceeds its type
As for b vs. (_Bool)b, an experiment indicates that they yield the
same result:
#include <stdio.h>
int main(void)
{
printf("sizeof (_Bool) = %zu\n", sizeof (_Bool));
_Bool b_two;
*(char*)&b_two = 2;
char c_two = 2;
printf("b_two = %d, (_Bool)b_two = %d\n", b_two, (_Bool)b_two);
printf("c_two = %d, (_Bool)c_two = %d\n", c_two, (_Bool)c_two);
return 0;
}
Output:
sizeof (_Bool) = 1
b_two = 2, (_Bool)b_two = 2
c_two = 2, (_Bool)c_two = 1
Hypothesis: _Bool has 1 value bit and 7 padding bits, and any
representation where any of the padding bits are 1 is a trap
representation. This means that any attempt to access the value
of b_two invokes undefined behavior -- even a cast to _Bool; the
compiler assumes that the stored value must be either 0 or 1, so
it doesn't need to normalize any non-zero value to 1, as it does
for types other than _Bool.
Perfectly possible. I don't think it is easy to tell if this is the
case of not. An implementation need not support bit-fields wider than
1 for _Bool even if _Bool has more than 1 value bit,
I don't know where you're getting this. My reading is that, if the
width of _Bool is N > 1, then programs are allowed to use _Bool
bitfields of width up to N, and therefore implementations are
required to support them.