Chris Lutz, , , : unsigned char myOneBitVariable:1; "unsigned char MyFourBitVariable: 4". , , , ..
. - 4 8 , . . GCC __attribute__((aligned(x))), MSVC - __declspec(align(x)). , . MSVC #pragma pack(x): http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx. MSVC : http://msdn.microsoft.com/en-us/library/83ythb65(VS.80).aspx. GCC __attribute__ ((__packed__), , , .
, , , Microsoft:
#ifndef _MSC_VER
#error This alignment solution / packing solution is only valid on MSC
#endif
#define M_ALIGN(x) __declspec(align(x))
struct S64Bits
{
unsigned char MyOneBitVariable:1;
int My32BitInt;
};
#pragma pack(1)
struct S32Bits
{
D_ALIGN(1) int My16BitVariable:16;
D_ALIGN(1) unsigned char Padding8Bits;
D_ALIGN(1) unsigned char MyOneBitVariable1:1;
D_ALIGN(1) unsigned char MyOneBitVariable2:1;
D_ALIGN(1) unsigned char MyOneBitVariable3:1;
D_ALIGN(1) unsigned char MyOneBitVariable4:1;
D_ALIGN(1) unsigned char MyFourBitVariable:4;
};
#pragma pack(pop)
'sizeof (S64Bits)' 8, . 'sizeof (S32Bits)' 4, . msvc 6 . . , . , , , , :
#define TEST_TYPE_SIZE(Type, Size) assert(sizeof(Type) == Size);
, . , , sizeof (mystructure), , , , . - - .
Karl Bielefeldt 4- uint8 , .