•  Back 
  •  C Language 
  •  Index 
  •  Tree View 
  •  Cross references 
  •  Help 
  •  Show info about hypertext 
  •  View a new file 
Topic       : C-Language Documentation
Author      : John Kormylo
Version     : C.HYP 1.0
Subject     : Documentation/C-Language
Nodes       : 233
Index Size  : 6362
HCP-Version : 3
Compiled on : Atari
@charset    : atarist
@lang       : en
@default    : 
@help       : Help
@options    : +g -i -s +x +z -t4
@width      : 75
View Ref-File[ Bit Fields ]

A way to pack fields with different numbers of bits is to use a
structure with bitfields:

struct {
  int high:8;             /* leftmost 8 bits */
  unsigned int flag:1;    /* 1 bit flag */
 } packed;

Members 'packed.high' and 'packed.flag' will behave like ordinary
variables except that they have a more limited range of values.

Only int and unsigned int can be used with bit fields.  A signed int
requires at least one bit for the sign, so that 'packed.high = 255'
and 'packed.high = -1' are equivalent.

See also Structures.