请教如何数据对齐?
请问各位高手:在VC和GCC中数据对齐是用#pragma pack(2) 指令吗?
我用C语言写的BMP文件头结构体本来是14字节的,但它总把这个结构体对齐到16字节。。。应该怎么办?
typedef unsigned char BYTE;
typedef short int UINT;
typedef short int WORD;
typedef unsigned long DWORD;
typedef long LONG;
typedef struct
{
short int bfType;
DWORD bfSize;
UINT bfReserved1;
UINT bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;
[解决办法]
#pragma pack(push, 1)
typedef struct
{
short int bfType;
DWORD bfSize;
UINT bfReserved1;
UINT bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;
#pragma pack(pop)