tmp/tmp7cor9e0q/{from.md → to.md}
RENAMED
|
@@ -1,59 +1,63 @@
|
|
| 1 |
### Bit-fields <a id="class.bit">[[class.bit]]</a>
|
| 2 |
|
| 3 |
A *member-declarator* of the form
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
[*Note 1*: Bit-fields straddle allocation units on some machines and
|
| 20 |
not on others. Bit-fields are assigned right-to-left on some machines,
|
| 21 |
left-to-right on others. — *end note*]
|
| 22 |
|
| 23 |
A declaration for a bit-field that omits the *identifier* declares an
|
| 24 |
*unnamed bit-field*. Unnamed bit-fields are not members and cannot be
|
| 25 |
-
initialized.
|
|
|
|
| 26 |
|
| 27 |
[*Note 2*: An unnamed bit-field is useful for padding to conform to
|
| 28 |
externally-imposed layouts. — *end note*]
|
| 29 |
|
| 30 |
As a special case, an unnamed bit-field with a width of zero specifies
|
| 31 |
alignment of the next bit-field at an allocation unit boundary. Only
|
| 32 |
-
when declaring an unnamed bit-field may the
|
| 33 |
-
*constant-expression* be equal to zero.
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
address-of operator `&` shall not be applied to a bit-field, so there
|
| 39 |
-
are no pointers to bit-fields. A non-const reference shall not be bound
|
| 40 |
-
to a bit-field ([[dcl.init.ref]]).
|
| 41 |
|
| 42 |
[*Note 3*: If the initializer for a reference of type `const` `T&` is
|
| 43 |
an lvalue that refers to a bit-field, the reference is bound to a
|
| 44 |
temporary initialized to hold the value of the bit-field; the reference
|
| 45 |
is not bound to the bit-field directly. See
|
| 46 |
[[dcl.init.ref]]. — *end note*]
|
| 47 |
|
| 48 |
-
If
|
| 49 |
-
of
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
the
|
| 53 |
-
|
| 54 |
-
value and the value of the bit-field
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
[*Example 1*:
|
| 57 |
|
| 58 |
``` cpp
|
| 59 |
enum BOOL { FALSE=0, TRUE=1 };
|
|
|
|
| 1 |
### Bit-fields <a id="class.bit">[[class.bit]]</a>
|
| 2 |
|
| 3 |
A *member-declarator* of the form
|
| 4 |
|
| 5 |
+
``` bnf
|
| 6 |
+
identifierₒₚₜ attribute-specifier-seqₒₚₜ ':' constant-expression brace-or-equal-initializerₒₚₜ
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
specifies a bit-field. The optional *attribute-specifier-seq* appertains
|
| 10 |
+
to the entity being declared. A bit-field shall not be a static member.
|
| 11 |
+
A bit-field shall have integral or enumeration type; the bit-field
|
| 12 |
+
semantic property is not part of the type of the class member. The
|
| 13 |
+
*constant-expression* shall be an integral constant expression with a
|
| 14 |
+
value greater than or equal to zero and is called the *width* of the
|
| 15 |
+
bit-field. If the width of a bit-field is larger than the width of the
|
| 16 |
+
bit-field’s type (or, in case of an enumeration type, of its underlying
|
| 17 |
+
type), the extra bits are padding bits [[basic.types]]. Allocation of
|
| 18 |
+
bit-fields within a class object is *implementation-defined*. Alignment
|
| 19 |
+
of bit-fields is *implementation-defined*. Bit-fields are packed into
|
| 20 |
+
some addressable allocation unit.
|
| 21 |
|
| 22 |
[*Note 1*: Bit-fields straddle allocation units on some machines and
|
| 23 |
not on others. Bit-fields are assigned right-to-left on some machines,
|
| 24 |
left-to-right on others. — *end note*]
|
| 25 |
|
| 26 |
A declaration for a bit-field that omits the *identifier* declares an
|
| 27 |
*unnamed bit-field*. Unnamed bit-fields are not members and cannot be
|
| 28 |
+
initialized. An unnamed bit-field shall not be declared with a
|
| 29 |
+
cv-qualified type.
|
| 30 |
|
| 31 |
[*Note 2*: An unnamed bit-field is useful for padding to conform to
|
| 32 |
externally-imposed layouts. — *end note*]
|
| 33 |
|
| 34 |
As a special case, an unnamed bit-field with a width of zero specifies
|
| 35 |
alignment of the next bit-field at an allocation unit boundary. Only
|
| 36 |
+
when declaring an unnamed bit-field may the width be zero.
|
|
|
|
| 37 |
|
| 38 |
+
The address-of operator `&` shall not be applied to a bit-field, so
|
| 39 |
+
there are no pointers to bit-fields. A non-const reference shall not be
|
| 40 |
+
bound to a bit-field [[dcl.init.ref]].
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
[*Note 3*: If the initializer for a reference of type `const` `T&` is
|
| 43 |
an lvalue that refers to a bit-field, the reference is bound to a
|
| 44 |
temporary initialized to hold the value of the bit-field; the reference
|
| 45 |
is not bound to the bit-field directly. See
|
| 46 |
[[dcl.init.ref]]. — *end note*]
|
| 47 |
|
| 48 |
+
If a value of integral type (other than `bool`) is stored into a
|
| 49 |
+
bit-field of width N and the value would be representable in a
|
| 50 |
+
hypothetical signed or unsigned integer type with width N and the same
|
| 51 |
+
signedness as the bit-field’s type, the original value and the value of
|
| 52 |
+
the bit-field compare equal. If the value `true` or `false` is stored
|
| 53 |
+
into a bit-field of type `bool` of any size (including a one bit
|
| 54 |
+
bit-field), the original `bool` value and the value of the bit-field
|
| 55 |
+
compare equal. If a value of an enumeration type is stored into a
|
| 56 |
+
bit-field of the same type and the width is large enough to hold all the
|
| 57 |
+
values of that enumeration type [[dcl.enum]], the original value and the
|
| 58 |
+
value of the bit-field compare equal.
|
| 59 |
|
| 60 |
[*Example 1*:
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
enum BOOL { FALSE=0, TRUE=1 };
|