Format of Structures Containing Bit Fields (OS/2)

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. Given the following structure:
struct s {
   char a;
   int b1:4;
   int b2:6;
   int b3:1;
   int :0;
   int b4:7;
   char c;
} 

struct s would be stored as follows:

  • The second row of the table counts the number of bits used and should be read vertically top to bottom. Bits are allocated from least-significant to most-significant within each byte. In the diagram above, the least significant bit is on the left.
  • This mapping is also true for aligned structures in C++ as long as the structure does not contain virtual base classes or virtual functions.



Data Mapping