0

Size of this union return 16 bytes (in C++Builder 2007).

typedef union
{
  struct
  {
    unsigned Type:2; 
    unsigned Prev:31;
    unsigned Next:31;
    unsigned SizeInBytes:32;
  };
} eMyUnion;

How i must modify this union definition, if i want sizeof(eMyUnion) = 12 bytes ?
(I want keep these fields and its sizes, but it can be reordered).
It is possible ?

timrau
  • 22,578
  • 4
  • 51
  • 64
Altivo
  • 490
  • 6
  • 13

1 Answers1

1
#pragma pack(push, 1)
  struct
  {
    unsigned Type:2; 
    unsigned Prev:31;
    unsigned Next:31;
    unsigned SizeInBytes:32;
  };
#pragma pack(pop)
John Zwinck
  • 239,568
  • 38
  • 324
  • 436