Page 123 - 6437
P. 123
Book title : C Programming
Book author : Nuha Ali
Book subject : C Programming Tutorial
Book book_id : 6495407
Book title : Telecom Billing
Book author : Zara Ali
Book subject : Telecom Billing Tutorial
Book book_id : 6495700
Bit Fields
Bit Fields allow the packing of data in a structure. This is especially useful when memory or
data storage is at a premium. Typical examples include:
Packing several objects into a machine word, e.g. 1 bit flags can be compacted.
Reading external file formats -- non-standard file formats could be read in, e.g.,
9-bit integers.
C allows us to do this in a structure definition by putting :bit length after the variable. For
example:
struct packed_struct {
unsigned int f1:1;
unsigned int f2:1;
unsigned int f3:1;
unsigned int f4:1;
126