From Jason Turner

[class.bit]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp7cor9e0q/{from.md → to.md} +33 -29
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
- specifies a bit-field; its length is set off from the bit-field name by
6
- a colon. The optional *attribute-specifier-seq* appertains to the entity
7
- being declared. The bit-field attribute is not part of the type of the
8
- class member. The *constant-expression* shall be an integral constant
9
- expression with a value greater than or equal to zero. The value of the
10
- integral constant expression may be larger than the number of bits in
11
- the object representation ([[basic.types]]) of the bit-field’s type; in
12
- such cases the extra bits are used as padding bits and do not
13
- participate in the value representation ([[basic.types]]) of the
14
- bit-field. Allocation of bit-fields within a class object is
15
- *implementation-defined*. Alignment of bit-fields is
16
- *implementation-defined*. Bit-fields are packed into some addressable
17
- allocation unit.
 
 
 
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 value of the
33
- *constant-expression* be equal to zero.
34
 
35
- A bit-field shall not be a static member. A bit-field shall have
36
- integral or enumeration type ([[basic.fundamental]]). A `bool` value
37
- can successfully be stored in a bit-field of any nonzero size. The
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 the value `true` or `false` is stored into a bit-field of type `bool`
49
- of any size (including a one bit bit-field), the original `bool` value
50
- and the value of the bit-field shall compare equal. If the value of an
51
- enumerator is stored into a bit-field of the same enumeration type and
52
- the number of bits in the bit-field is large enough to hold all the
53
- values of that enumeration type ([[dcl.enum]]), the original enumerator
54
- value and the value of the bit-field shall compare equal.
 
 
 
 
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 };