JTC1/SC22/WG14
N743
WG14 N743 J11 97-106
Bit-field Enhancements
David Keaton
1997-06-27
All relevant parts of the standard have been listed, whether they
require changes or not. Caveat: The changes are made against C9X
draft 10-pre3 and must be merged with other changes made at the London
meeting.
6.1.2.6 Compatible type and composite type, paragraph 1
This already specifies the correct rules for extended bit-fields. The
types and widths must match.
6.2.1.1 Characters and integers, paragraph 1
Replace with the following:
The following conversions are called the "integral promotions."37
Any of these types may be used in an expression wherever an "int" or
"unsigned int" may be used.
- a "bool" or a "bool" bit-field
- a "char," "signed char," or "unsigned char," or bit-fields
of these types
- a "short," "signed short," or "unsigned short," or
bit-fields of these types
- an "int," "signed int," or "unsigned int" bit-field
- an enumeration type
If an "int" can represent all the values of the original type, the
value is converted to "int;" otherwise, it is converted to "unsigned
int."
A "long," "signed long," or "unsigned long" bit-field may be used in
an expression wherever a "long" or "unsigned long" may be used. If a
"long" can represent all values of the original type, the value is
converted to a "long;" otherwise, it is converted to an "unsigned
long."
A "long long," "signed long long," or "unsigned long long" bit-field
may be used in an expression wherever a "long long" or "unsigned long
long" may be used. If a "long long" can represent all the values of
the original type, the value is converted to a "long long;"
otherwise, it is converted to an "unsigned long long."
All other arithmetic types are unchanged by the integral promotions.
- 2 -
6.5.2 Type specifiers, paragraph 4
Replace with the following:
Each of the above comma-separated sets designates the same type,
except that for bit-fields, the types "short," "int," "long," and
"long long" may differ from their signed varieties.
6.5.2.1 Structure and union specifiers, paragraph 8
Replace with the following (but merge with other changes from this
meeting first):
A bit-field shall have a type that is a qualified or unqualified
version of one of the following.
- "bool"
- "char," "signed char," or "unsigned char"
- "short," "signed short," or "unsigned short"
- "int," "signed int," or "unsigned int"
- "long," "signed long," or "unsigned long"
- "long long," "signed long long," or "unsigned long long"
Whether the high-order bit position of a (possibly qualified)
``plain'' "char," "short," "int," "long," or "long long" bit-field is
interpreted as a sign bit is implementation-defined. A bit-field is
interpreted as an integral type consisting of the specified number of
bits.
A "bool" value can successfully be stored in a "bool" bit-field of any
nonzero size.
If the value "true" or "false" is stored into a bit-field of type
"bool" of any nonzero size (including a one bit bit-field), the
original bool value and the value of the bit-field shall compare
equal.
6.5.2.1 Structure and union specifiers, paragraph 9
The existing packing rules suffice. Note that two bit-fields need not
have the same type to be packed together. This is what we want.
- 3 -
I.2 Undefined behavior, paragraph 1
Replace this:
- A bit-field is declared with a type other than "int," "signed int,"
or "unsigned int" (6.5.2.1).
with the following:
- A bit-field is declared with a type other than the following
(6.5.2.1).
- "bool"
- "char," "signed char," or "unsigned char"
- "short," "signed short," or "unsigned short"
- "int," "signed int," or "unsigned int"
- an enumeration type
- "long," "signed long," or "unsigned long"
- "long long," "signed long long," or "unsigned long long"
I.3.9 [Implementation-defined behavior] Structures, unions,
enumerations, and bit-fields; paragraph 1
Replace this:
- Whether a ``plain'' "int" bit-field is treated as a "signed int"
bit-field or as an "unsigned int" bit-field (6.5.2.1).
with the following:
- Whether a ``plain'' "char," "short," "int," "long," or "long long"
bit-field is treated as being signed (6.5.2.1).
I.5.8 [Common extensions] Non-"int" bit-field types
Change the title to the following.
Extended bit-field types.
Replace paragraph 1 with the following.
Types other than standard integer types can be declared as bit-fields,
with appropriate maximum widths (6.5.2.1).