Format of Structures Containing Bit Fields (Windows)

The C++ compiler may generate extra fields for classes that contain base classes or virtual functions. Objects of these types may not conform to the mapping shown below.

Type struct
Size The sum of the sizes for each type in the struct plus padding for alignment
Alignment Each structure is aligned according to the structure alignment rules.
Storage Mapping Here is a definition of a structure that contains bit fields, followed by a diagram of its storage.
struct s {
   char a;
   int b1:4;
   int b2:6;
   int b3:1;
   int :0;
   int b4:7;
   char c;
}
  • a is stored in byte 0
  • full padding in bytes 1, 2, 3
  • b1, b2, b3 begin in byte 4 and end in byte 5 with 5 bits of padding in byte 5
  • full padding in bytes 6 and 7
  • b4 begins in byte 8 with one bit of padding in byte 8
  • full padding in bytes 9, 10, 11
  • c is stored in byte 12
  • full padding in bytes 13, 14, 15

 



Data Mapping