...
Code Block |
---|
struct { unsigned int a: 8; } bits = {255}; int main(void) { printf(LANG ", unsigned 8-bit field promotes to %s.\n", (bits.a << 24) < 0 ? "signed" : "unsigned"); } |
...
The first interpretation is that when this value is used as an rvalue (e.g., lvalue = rvalue), the type is "unsigned int
" as declared. An unsigned int
cannot be represented as an int
, so integer promotions require that this be an unsigned int
, and hence "unsigned".
The second interpretation is that this is an 8-bit integer. As a result, this eight bit value can be represented as an int
, so integer promotions require that it be converted to int
, and hence "signed".
This also has implications for signed long long
and unsigned long long
types. For example, gcc will also interpret the following as an eight bit value and promote it to int
:
...