|
|
1.1 root 1:
2:
3: bit-fields Definition bit-fields
4:
5:
6:
7:
8: A bit-field is a member of a structure or union that is defined
9: to be a cluster of bits. It provides a way to represent data
10: compactly. For example, in the following structure
11:
12:
13: struct example {
14: int member1;
15: long member2;
16: unsigned int member3 :5;
17: }
18:
19:
20: member3 is declared to be a bit-field that consists of five bits.
21: A colon `:' precedes the integral constant that indicates the
22: _w_i_d_t_h, or the number of bits in the bit-field. Also, the bit-
23: field declarator must include a type, which must be one of int,
24: signed int, or unsigned int.
25:
26: A bit-field that is not given a name may not be accessed. Such
27: an object is useful as ``padding'' within an object so that it
28: conforms to a template designed elsewhere.
29:
30: A bit-field that is unnamed and has a length of zero can be used
31: to force adjacent bit-fields into separate objects. For example,
32: in the following structure
33:
34:
35: struct example {
36: int member1;
37: int member2 :5;
38: int :0;
39: int member3 :5;
40: };
41:
42:
43: the zero-length bit-field forces member2 and member3 to be writ-
44: ten into separate objects.
45:
46: Finally, it is illegal to take the address of a bit-field.
47:
48: ***** See Also *****
49:
50: bit, bit map, byte, definitions
51:
52: ***** Notes *****
53:
54: Because bit-fields have many implementation-specific properties,
55: they are not considered to be highly portable. Bit-fields use
56: minimal amounts of storage, but the amount of computation needed
57: to manipulate and access them may negate this benefit. Bit-
58: fields must be kept in integral-sized objects because many
59: machines cannot directly access a quantity of storage smaller
60: than a ``word'' (a word is generally used to store an int).
61:
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.