Harald van Dijk said:
Harald said:
If the implementation does that, I would argue that the type of errno
is not int (even if int has 16 bits). Instead, the type is int : 16.
A bit-field's width is not part of the type of the bit-field. It merely
determines how much space that bit field takes up. [examples snipped]
In each case, the standard talks about the type of a bit field without
while referring only to standard-defined type names, and not referring
to the width.
It's interesting that one of the examples you gave was 6.3.1.1p2. I'll
quote another part of it:
"If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int. These
are called the integer promotions."
Here, "the original type" does include the bit field's width.
I don't believe it does.
Here's the context (I'm quoting from n1256, which does differ from
C99; I haven't gone back to check what the change bar refers to):
The following may be used in an expression wherever an int or
unsigned int may be used:
-- An object or expression with an integer type whose integer
conversion rank is less than or equal to the rank of int and
unsigned int. [n1256 has a change bar here]
-- A bit-field of type _Bool, int, signed int, or unsigned int.
If an int can represent all values of the original type, the value
is converted to an int; otherwise, it is converted to an unsigned
int. These are called the _integer promotions_. All other types
are unchanged by the integer promotions.
As far as I can tell, given a bit field "unsigned int bf:3;", the
"original type" of bf is unsigned int.
This does make a difference. If the "original type" is "unsigned
int:3", then the value would be promoted to type int; if the original
type is unsigned int, then the value would be (trivially) promoted to
type unsigned int. But I can't think of a case where the difference
would be visible in the behavior of a program.
The standard
is not consistent in treating width as part of the type.
It's not as clear as it might be, but I *think* it's consistent.