L
Lawrence Kirby
In message <[email protected]>
It IS the case that bit-fields can be loaded and stored without affecting
anything else, as far as C is concerned, even if the implementation has
to jump through hoops to achieve it.
The statement is also true of ints. The main thing about bitfields is that
they don't necessarily occupy a while number of bytes i.e. a
particular byte may be used by more than one distinct object.
I'd agree that there's a potential difference in the implementation
(although I'm sure there are implementations that load & store chars
like a bitfield, and others that can load aligned bitfields like x.b as
a char). But is that sufficient reason to cause such a significant
difference in the semantics?
IMO implementation details are not a big issue here, they don't make much
difference one way or the other. The issue is how you interpret the C
standard. It is just one case of the overall value-preserving nastiness.
The very decision to adopt "value-preserving" promotions was to minimise
unexpected behaviour.
In which case it singularly failed. Having unsigned types switch to signed
types through non-obvious rules is what most people find "unexpected".
Having bitfields alone be "unsigned-preserving" would
be rather unexpected, surely?
Not if you viewed the type of the bit-field as unsigned int to start with.
In that case having a value of type unsigned int "promote" to int would be
odd indeed. However as per my other post it appears that shorter unsigned
int bitfields do promote to int.
I suppose it's just unexpected if you have my view of bitfields though -
I automatically think of "unsigned :8" as just being a custom
sub-integer type, akin to unsigned char. Maybe you think of it as an
unsigned int which just happens to be not allocated all its bits.
Bit-fieldness does seem to be a second class property of types.
I think 6.7.2.1p9 disagrees with you. The bitfield's type may not have a
name, but it is a type.
Whatever is meant by "is interpreted as". Is it a type (modifier) or isn't
it? If bit-fields are part of the type system why aren't they mentioned in
6.2.5?
Lawrence