From Jason Turner

[class.bit]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_w6lyob5/{from.md → to.md} +28 -16
tmp/tmp_w6lyob5/{from.md → to.md} RENAMED
@@ -1,6 +1,6 @@
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
@@ -12,49 +12,61 @@ 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. Bit-fields straddle allocation units on some machines
18
- and not on others. Bit-fields are assigned right-to-left on some
19
- machines, left-to-right on others.
 
 
20
 
21
  A declaration for a bit-field that omits the *identifier* declares an
22
- *unnamed* bit-field. Unnamed bit-fields are not members and cannot be
23
- initialized. An unnamed bit-field is useful for padding to conform to
24
- externally-imposed layouts. As a special case, an unnamed bit-field with
25
- a width of zero specifies alignment of the next bit-field at an
26
- allocation unit boundary. Only when declaring an unnamed bit-field may
27
- the value of the *constant-expression* be equal to zero.
 
 
 
 
28
 
29
  A bit-field shall not be a static member. A bit-field shall have
30
  integral or enumeration type ([[basic.fundamental]]). A `bool` value
31
  can successfully be stored in a bit-field of any nonzero size. The
32
  address-of operator `&` shall not be applied to a bit-field, so there
33
  are no pointers to bit-fields. A non-const reference shall not be bound
34
- to a bit-field ([[dcl.init.ref]]). If the initializer for a reference
35
- of type `const` `T&` is an lvalue that refers to a bit-field, the
36
- reference is bound to a temporary initialized to hold the value of the
37
- bit-field; the reference is not bound to the bit-field directly. See 
38
- [[dcl.init.ref]].
 
 
39
 
40
  If the value `true` or `false` is stored into a bit-field of type `bool`
41
  of any size (including a one bit bit-field), the original `bool` value
42
  and the value of the bit-field shall compare equal. If the value of an
43
  enumerator is stored into a bit-field of the same enumeration type and
44
  the number of bits in the bit-field is large enough to hold all the
45
  values of that enumeration type ([[dcl.enum]]), the original enumerator
46
  value and the value of the bit-field shall compare equal.
47
 
 
 
48
  ``` cpp
49
  enum BOOL { FALSE=0, TRUE=1 };
50
  struct A {
51
  BOOL b:1;
52
  };
53
  A a;
54
  void f() {
55
  a.b = TRUE;
56
  if (a.b == TRUE) // yields true
57
- { /* ... */ }
58
  }
59
  ```
60
 
 
 
 
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
 
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 };
60
  struct A {
61
  BOOL b:1;
62
  };
63
  A a;
64
  void f() {
65
  a.b = TRUE;
66
  if (a.b == TRUE) // yields true
67
+ { ... }
68
  }
69
  ```
70
 
71
+ — *end example*]
72
+